Assignment 3

Coding
from datetime import datetime

"""CONFIG"""# maximum number of pizzas in one order
number_of_order = 3# delivery charge (in $)delivery_charge = 3.00# list of dictionaries (pizzas) with name and price
pizza_available = (
    {"name": "Tuna Pizza","price": 15.00},    {"name": "Cheese Pizza","price": 15.00},    {"name": "Pepperoni Pizza","price": 16.00},    {"name": "Honey Garlic Chicken Pizza","price": 17.00},    {"name": "Vegetarian Pizza","price": 17.00},    {"name": "Supreme Pizza", "price": 18.00}
)

# class with default order detailsclass Order():
    def __init__(self):
        self.pickup = True
        self.name = ""        self.address = None        self.phone = None
        self.number_pizzas = 0        self.pizzas = []

        self.total_cost = 0

# function for order summarydef print_order(order):
    print(" Name: {}".format(order.name))
    print(" Order type: {}".format("pickup"if order.pickup
    else "Delivery"))
    if not order.pickup:
        print(" Delivery address: {}".format(order.address))
        print(" Customer phone number: {}".format(order.phone))
    print("\n Order summary:\t\t\t\tPrice each:\tSubtotal:")
    for pizza in order.pizzas:
        print(" \t{}x{:<22}\t${:<6.2f}\t\t${:>5.2f}".format(
            pizza['amount'], pizza['name'],            pizza['price'], pizza['price']*pizza['amount']))

        if not order.pickup:
            print(" Delivery charge\t\t\t\t\t${:>5.2f}".format(delivery_charge))
            print(" {:61}------".format(""))
            print(" {:54} Total: ${:.2f}".format("", order.total_cost))

# List to hold all completed ordersorders=[]

# Sorts pizza list by price, then alphabeticallypizzas_available = sorted(pizza_available, key=lambda k: (k["price"], k["name"]))
class CancelOrder(Exception):
    pass# Keep getting orders, only exits through sys.exit()while True:
    # try...except to catch CancelOrder exception    try:
        print("\nNew order")
        order = Order()

    # Get name info        validcharacters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ "        while True:
            order.name = input("Enter customer name:")
            if all(char in validcharacters for char in order.name):
                print("Your name is " + order.name)
                break            print("That's invalid, please try again. Please enter characters A-Z and space only")

     # Get delivery/pickup type        ordertype1 = "Pp"        ordertype2 = "Dd"
        while True:
            typeoforder = input("Type of order:")
            if all(char in ordertype1 for char in typeoforder):
                print("Your type of order is pick up")

            if all(char in ordertype2 for char in typeoforder):
                print("Your type of order is delivery")
                order.pickup = False                order.address = input("Enter your address:")
                break            print("That's invalid, please try again. Please enter characters of P/p for pickup or D/d for delivery "                  "only")


        while True:
                try:
                    order.phone = int(input("Enter your phone number:"))
                except ValueError:
                    print("Not an integer! Please try again.")
                    continue                else:

                    break    except CancelOrder:
        sys.exit()

Comments

Popular posts from this blog

WAN Technology

LO3 - Know the features and functions of information systems

WDD - LO1 - MANAGE SECURE SITES