# functions go here loop = 0 def make_statement(statement, decoration): """Emphasises headings by adding decoration at the start and end""" print(f"{decoration * 3} {statement} {decoration * 3}") def not_blank(question): """Checks that a user response is not blank""" while True: response = input(question) if response != "": return response print("Sorry, this can't be blank. Please try again. \n") def int_check(question, low, high): """checks that users enter an integer that is more than 0""" error = f"Oops - please enter an integer between {low} and {high}." while True: try: # change response to an integer to check it's more than zero response = int(input(question)) if low <= response <= high: return response else: print(error) except ValueError: print(error) def string_check(question, valid_ans_list=('yes', 'no'), num_letters=1): """checks that users enter the full word or the n letters of a word from a list of valid responses""" while True: response = input(question).lower() for item in valid_ans_list: # check if response is full word if response == item: return item # check if it's the first letter elif response == item[:num_letters]: return item print(f"Please choose an option from {valid_ans_list}") def instructions(): make_statement("Instructions", "๐Ÿงพ") print(''' The menu will display all the pizzas we sell, a code for them, and their availability and price. To order a pizza, enter the code for the pizza that you want to order and then how many you would like to buy. Should you desire, you can add extra toppings or modifications to your pizza. You can order up to 5 pizzas. You can pick up your order or have it delivered to your home. You can then pay with cash or credit at the place you receive your order. ''') def menu(): make_statement("Menu", "๐Ÿ•") print(f''' Code | Pizza | Type 1 | Pepperoni | Traditional($5) | 2 | Cheese | 3 | Hawaiian | 4 | Margarita | 5 | Vege | 6 | Chicken | Gourmet($10) | 7 | Chicken Again | 8 | Artichoke | 9 | Truffle | 10 | Seafood | ''') def toppings_menu(): print("") make_statement("Toppings", "๐Ÿง‚") print(''' Code | Name | Price 1 | Mayonnaise | $2 | 2 | Barbeque Sauce | 3 | Extra Cheese | 4 | Herbs | $3 | 5 | Sausage | ''') print("") def diet_menu(): print("") make_statement("Dietary Requirements", "๐ŸŒพ") print(''' Code | Name | Price 1 | Gluten Free | $2 | 2 | Dairy Free | 3 | Vegetarian | $3 | 4 | Vegan | ''') print("") # lists with valid answers for string check for pay method and way of order collection price = 0 payment_ans = ['cash', 'credit'] collect_ans = ['delivery', 'pickup'] make_statement("Pizza Purchasing Program", "๐Ÿ•") # optional instructions for new users print() want_instructions = string_check("Would you like to view your instructions? ") if want_instructions == "yes": instructions() # ask for order details until the user adds up to 5 pizzas while loop < 5: print() menu() print() # ask user for the flavour of pizza they would like to order pizza = int_check("What is the code of the pizza you would like to order? ", 1, 10) if 1 < pizza <= 5: price += 5 else: price += 10 toppings_ask = string_check("Would you like to add toppings to this pizza? ") # if user wants toppings for this pizza, display the toppings menu and ask which one they want if toppings_ask == "yes": toppings_menu() # add topping price to total price depending on type of topping toppings = int_check("What is the code of the toppings would you like to add to this pizza? ", 1, 5) if toppings <= 3: price += 2 else: price += 3 else: toppings = 0 diet_ask = string_check("Would you like to specify any dietary requirements for this pizza?") # ask user if they have any diet requirements and show available ones if diet_ask == "yes": diet_menu() # genetic dietary requirements are cheaper than chosen like vegetarian diet = int_check("What dietary requirement would you like to add to this pizza?", 1, 5) if diet <= 2: price += 2 else: price += 3 else: diet = 0 loop += 1 # ask user if they want to add another pizza to their cart if loop < 5: do_loop = string_check("Would you like to add another pizza to your order? ") # if they don't want another pizza, leave the loop if do_loop == "no": break else: break # inform the user of the amount of pizzas they have added. If they reach the max, tell them then continue if loop == 5: print("You have added the maximum amount of pizzas (5) to your cart.") else: if loop == 1: print(f"You have {loop} pizza in your cart.") else: print(f"You have {loop} pizzas in your cart.") collect = string_check("Would you like to pick up your order or have it delivered to you? Delivery orders cost an " "extra 10% surcharge ", collect_ans, 1) # apply surcharge to price and ask for address if collect == "delivery": address = input("Where do you want us to deliver your order? ") surcharge = 1.1 price = price * surcharge # ask for users name, contact and payment method name = not_blank("What is your name? ") contact = not_blank("Please enter your email or phone number so we can contact you when your order is ready ") pay_method = string_check(f"Your order costs ${price}. Will you be paying with cash or credit? ", payment_ans, 2) # end program with friendly message print() print("Thank you for ordering from the Pizza Purchasing Program. We will contact you when your order is ready ") print()