Python Challenge 4

Python Challenge

This code allows you to order a McFlurry at a popular high street restaurant. It allows you to order multiple items, calculates the cost and when you exit from the order page it prints a receipt. See if you can modify the code to build an ordering system for a popular high street coffee shop or other shop of your choice. Develop the code further to add in more products for your shop and any other improvements you can think of. Hint: if your code starts to look too big, use decomposition to break it down into smaller functions that could each be on a seperate menu (i.e when you order at a mcdonalds touch screen you have a main menu then you can select burgers, sides, drinks etc from different meu's).

 

cost=0
order_number=0
mcflurry_list=[]

def mcflurry_menu():
    global cost
    print("")
    print("Choose your Mcflurry")
    print("a.Chocolate, b.Strawberry or c.Vanilla")
    mcflurry_select=(input("Select a, b or c or x to exit: "))
    if mcflurry_select== "a":
        print("a. Chocolate selected")
        mcflurry_list.append("Chocolate Mcflurry")
        cost=cost+1.5
        mcflurry_menu()
    elif mcflurry_select=="b":
        print("b. Strawberry selected")
        mcflurry_list.append("Strawberry Mcflurry")
        cost=cost+1.8
        mcflurry_menu()
    elif mcflurry_select=="c":
        print("c. Vanilla selected")
        mcflurry_list.append("Vanilla Mcflurry")
        cost=cost+1.2
        mcflurry_menu()
    elif mcflurry_select=="x":
        print("x exit")
        print_order()
    else:
        print("Sorry size not recognised")
        mcflurry_menu()
def print_order():
    global order_number
    global cost
    order_number=order_number+1
    print("Order number: ", order_number)
    print("Your order is: ", mcflurry_list)
    print("Payment due: £", cost)
    file=open('mcflurry_bill' + str(order_number) + '.doc','w')
    file.write("Your order:\n")
    file.write("Order = " + repr(mcflurry_list) + "\n")
    file.write("Cost = £" + repr(cost) + "\n")
    file.close()
    cost=0
    mcflurry_list.clear()
    mcflurry_menu()
mcflurry_menu()