# --- Pizza Menu Stored in Code --- pizza_menu = [ ["Margherita", 8.50], ["Pepperoni", 9.00], ["BBQ Chicken", 10.00], ["Veggie Delight", 9.00], ["Meatlovers", 11.50], ["Hawaiian", 9.50], ["Cheeseburger", 10.00], ["Chicken Cranberry", 11.00], ["Beef & Onion", 9.50], ["Garlic & Cheese", 8.00] ] extras_menu = [ ["Drink", 2.50], ["Fries", 3.00], ["Extra Cheese", 1.50], ["Garlic Sauce", 1.00], ["Dipping Box", 3.50] ] # --- Function to display the pizza menu --- def display_menu(): print("\n--- Pizza Menu ---") for i, item in enumerate(pizza_menu, 1): print(f"{i}. {item[0]} - ${item[1]:.2f}") def display_extras(): print("\n--- Optional Extras ---") for i, item in enumerate(extras_menu, 1): print(f"{i}. {item[0]} - ${item[1]:.2f}") # --- Function to make sure input is not blank --- def not_blank(question): while True: response = input(question).strip() if response != "": return response print("This can't be blank. Try again.") # --- Function to check string input against a list of valid options --- def string_check(question, valid_ans_list, num_letters=1): while True: response = input(question).lower() for item in valid_ans_list: if response == item or response == item[:num_letters]: return item print(f"Choose from {valid_ans_list}") def get_valid_phone(): while True: phone = input("Enter your phone number (NZ): ").strip() if phone.isdigit() and 9 <= len(phone) <= 11 and phone.startswith(("02", "03", "04", "06", "07", "09")): return phone print("Invalid phone number. Try again (must be NZ format).") def get_valid_address(): while True: address = input("Enter your address: ").strip() # Must be at least 3 characters if len(address) < 3: print("Address is too short.") continue # Must include at least one number if not any(char.isdigit() for char in address): print("Address must include a number (e.g. house number).") continue # Must include at least one letter if not any(char.isalpha() for char in address): print("Address must include letters (e.g. street name).") continue return address def get_order(): order_list = [] max_pizzas = 5 while True: try: num_pizzas = int(input("How many pizzas would you like to order? (1–5): ")) if 1 <= num_pizzas <= max_pizzas: break else: print(f"Please enter a number between 1 and {max_pizzas}.") except ValueError: print("Please enter a valid number.") display_menu() # Just in case they forgot the options for i in range(num_pizzas): while True: try: choice = int(input(f"Select pizza #{i + 1} (1–{len(pizza_menu)}): ")) if 1 <= choice <= len(pizza_menu): selected = pizza_menu[choice - 1] order_list.append(selected) print(f"Added: {selected[0]} - ${selected[1]:.2f}") break else: print("That number isn't on the menu.") except ValueError: print("Please enter a number.") return order_list def get_extras(): extras_order = [] want_extras = string_check("Do you want to add extras? (yes/no): ", ["yes", "no"], 1) if want_extras == "yes": display_extras() while True: try: choice = input("Enter the number of the extra you want (or 'x' to stop): ").strip().lower() if choice == "x": break choice = int(choice) if 1 <= choice <= len(extras_menu): selected = extras_menu[choice - 1] extras_order.append(selected) print(f"Added: {selected[0]} - ${selected[1]:.2f}") else: print("Invalid number.") except ValueError: print("Enter a number or 'x' to stop.") return extras_order # --- Function to get customer details --- def get_customer_details(): name = not_blank("Enter your name: ").capitalize() + "." phone = get_valid_phone() delivery_method = string_check("Pickup or delivery? ", ["pickup", "delivery"], 1) address = "" if delivery_method == "delivery": address = get_valid_address() return { "name": name, "phone": phone, "delivery_method": delivery_method, "address": address } # --- Main program --- def main(): all_items = [] # to hold all ordered items (pizzas + extras) total = 0 show_menu = string_check("Do you want to see the menu? (yes/no): ", ["yes", "no"], 1) if show_menu == "yes": display_menu() want_extras_menu = string_check("Would you like to see the extras menu? (yes/no): ", ["yes", "no"], 1) if want_extras_menu == "yes": display_extras() # --- Get customer details --- customer = get_customer_details() # --- Get pizza order --- order = get_order() all_items.extend(order) # --- Get extras --- extras = get_extras() all_items.extend(extras) # --- Add delivery fee if needed --- if customer["delivery_method"] == "delivery": delivery_fee = 3.00 all_items.append(["Delivery Fee", delivery_fee]) # --- Build order summary --- summary_lines = ["🍕 PIZZA ORDER SUMMARY 🍕\n", f"Customer: {customer['name']}", f"Phone: {customer['phone']}"] if customer["delivery_method"] == "delivery": summary_lines.append(f"Address: {customer['address']}") summary_lines.append(f"Order Type: {customer['delivery_method'].capitalize()}\n") summary_lines.append("Items Ordered:") for item in all_items: summary_lines.append(f"- {item[0]}: ${item[1]:.2f}") total += item[1] summary_lines.append(f"\nTotal Cost: ${total:.2f}") # --- Confirm Order --- confirm = string_check("Confirm order? (yes/no): ", ["yes", "no"], 1) if confirm == "yes": for line in summary_lines: print(line) # --- Write to file --- with open("order_log.txt", "a", encoding="utf-8") as file: file.write("\n".join(summary_lines)) file.write("\n" + "-" * 40 + "\n") else: print("Order cancelled.") # Run the program main()