import pandas def string_check(question, valid_list=('yes', 'no'), num_letters=1): """Checks that users enter the full word or the first 'n' letters from a list""" while True: response = input(question).strip().lower() for item in valid_list: item_low = item.lower() if response == item_low or response == item_low[:num_letters]: return item print(f"Please choose an option from {valid_list}") def instructions(): print("Pizza Paladin Instructions ℹ️") print(""" The program will record the users data that they entered, then proceed to the main menu of what Pizza Paladin offers. The program proceeds by asking would you like to pick-up or deliver the pizza to your address. You enter 'Pick-up' or 'Deliver' Once you have ordered your pizza (up to 5 maximum allowed), or entered the exit code (‘xxx’), the program will display the receipt information regarding the customers order and information, writing the data to a text file. For each customer should enter ... ------ (IF PICK-UP WAS CHOSEN) ------ - Their name - Their age - Phone number - The payment method (cash / credit) ------ (IF DELIVERY WAS CHOSEN) ------ - Their name - Their age - Phone number - Address - The payment method (cash / credit) The program will record the users data that they entered, then proceed to the order by printing a receipt """) def make_statement(statement, decoration, lines=1): middle = f"{decoration * 3} {statement} {decoration * 3}" top_bottom = decoration * len(middle) if lines == 1: print(middle) elif lines == 2: print(middle) print(top_bottom) else: print(top_bottom) print(middle) print(top_bottom) def not_blank(question): """Checks that a user response is not blank""" while True: response = input(question).strip() if response != "": return response print("Sorry, this can't be blank. Please try again.\n") def int_check(question): """Checks users enter an integer that is more than zero (or the 'xxx' exit code)""" error = "Oops - please enter an integer." while True: response = input(question).lower() if response == "xxx": return response try: response = int(response) if response > 0: return response else: print(error) except ValueError: print(error) def currency(x): """Formats numbers as currency ($#.##)""" return "${:.2f}".format(x) # Variables MAX_PIZZAS = 5 pizzas_sold = 0 payment_ans = ('cash', 'credit') yes_no_list = ('yes', 'no') CREDIT_SURCHARGE = 0.025 DELIVERY_FEE = 10 pizza_list = ["Pepperoni", "Hawaiian", "Margherita", "BBQ Chicken", "Meat Lovers", "Cheese Pizza", "Veggie Pizza", "Kebab Pizza", "Spaghetti Pizza", "Smash Burger"] pizza_sizes = ["Small", "Medium", "Large"] pizza_sizes_cost = [2.70, 3.50, 4.20] special_paladin_pizzas = ["Sushi Pizza", "S'more Pizza"] extra_toppings = ["Extra cheese", "Mushrooms", "Onions", "Pineapple", "Green Peppers"] pizza_cost = [8.30] * len(pizza_list) special_prices = [6.70, 6.40] topping_prices = [1.80, 1.20, 1.20, 1.30, 1.10] # Main routine starts here while True: make_statement(statement="Welcome To Pizza Paladin!", decoration="🍕") print() want_instructions = string_check("Do you want to see the instructions? ", yes_no_list) if want_instructions == "yes": instructions() print() # Customer name name = not_blank("Name (or 'xxx' to quit): ") if name.lower() == "xxx": print("Order cancelled. Hope you come back and order a pizza from Pizza Paladin!") break print() # Phone Number phone_number = not_blank("What is your phone number? ") print() # Ask Pick up or Delivery delivery_choice = None address = "" while True: pickup_or_delivery = string_check("Would you like delivery or pick up? ", ("delivery", "pick up"), 3) if pickup_or_delivery == "delivery": confirm_delivery = string_check("There is a $10 delivery fee. Would you like to proceed? ", yes_no_list) if confirm_delivery == "yes": delivery_choice = "delivery" address = not_blank("Please enter your address: ") break else: delivery_choice = "pick up" break print() # Main menu make_statement(statement="Pizza Paladin Main Menu", decoration="🍕") print("\n--- Gourmet Pizzas ---") for i, pizza in enumerate(pizza_list, start=1): print(f"{i}. {pizza} - {currency(pizza_cost[i - 1])}") print("\n--- Pizza Sizes ---") for i, size in enumerate(pizza_sizes, start=len(pizza_list) + 1): print(f"{i}. {size} - {currency(pizza_sizes_cost[i - len(pizza_list) - 1])}") print("\n--- Special Pizzas ---") for i, special in enumerate(special_paladin_pizzas, start=len(pizza_list) + len(pizza_sizes) + 1): print(f"{i}. {special} - {currency(special_prices[i - (len(pizza_list) + len(pizza_sizes) + 1)])}") print("\n--- Extra Toppings ---") for i, topping in enumerate(extra_toppings, start=len(pizza_list) + len(pizza_sizes) + len(special_paladin_pizzas) + 1): print( f"{i}. {topping} - {currency(topping_prices[i - (len(pizza_list) + len(pizza_sizes) + len(special_paladin_pizzas) + 1)])}") print() # Pizza order tracking pizzas_sold = 0 order_summary = [] while pizzas_sold < MAX_PIZZAS: # Gourmet Pizza Selection while True: choose_pizza_num = input(f"Choose a gourmet pizza number (1-{len(pizza_list)}) or type 'xxx' to quit: ").strip() if choose_pizza_num.lower() == "xxx": choose_pizza_num = "xxx" break if choose_pizza_num.isdigit(): choose_pizza_num = int(choose_pizza_num) if 1 <= choose_pizza_num <= len(pizza_list): pizza_name = pizza_list[choose_pizza_num - 1] pizza_price = pizza_cost[choose_pizza_num - 1] print(f"You chose {pizza_name}, this costs {currency(pizza_price)}") break print(f"Please choose a number between 1 - {len(pizza_list)}") if choose_pizza_num == "xxx": break print() # Pizza Size's while True: size_num = input(f"Choose pizza size number ({len(pizza_list) + 1}-{len(pizza_list) + len(pizza_sizes)}): ").strip() if size_num.lower() == "xxx": size_num = "xxx" break if size_num.isdigit(): size_num = int(size_num) if len(pizza_list) + 1 <= size_num <= len(pizza_list) + len(pizza_sizes): size_index = size_num - len(pizza_list) - 1 size_name = pizza_sizes[size_index] size_price = pizza_sizes_cost[size_index] print(f"You chose {size_name}, this costs {currency(size_price)}") break print(f"Please choose a number between {len(pizza_list)+1} - {len(pizza_list) + len(pizza_sizes)}") if size_num == "xxx": break print() pizza_total = pizza_price + size_price order_summary.append((f"{pizza_name} ({size_name})", pizza_total)) # --- Extra toppings --- extra_toppings_pizza = string_check("Would you like extra toppings? ", yes_no_list) if extra_toppings_pizza == "yes": while True: topping_num = input( f"Choose topping number ({len(pizza_list) + len(pizza_sizes) + len(special_paladin_pizzas) + 1}-" f"{len(pizza_list) + len(pizza_sizes) + len(special_paladin_pizzas) + len(extra_toppings)}): ").strip() if topping_num.lower() == "xxx": break if topping_num.isdigit(): topping_num = int(topping_num) if len(pizza_list) + len(pizza_sizes) + len(special_paladin_pizzas) + 1 <= topping_num <= len(pizza_list) + len(pizza_sizes) + len(special_paladin_pizzas) + len(extra_toppings): topping_index = topping_num - (len(pizza_list) + len(pizza_sizes) + len(special_paladin_pizzas)) topping_name = extra_toppings[topping_index - 1] topping_price = topping_prices[topping_index - 1] print(f"You chose {topping_name}, this costs {currency(topping_price)}") order_summary.append((f"Extra: {topping_name}", topping_price)) break print(f"Please choose a number between {len(pizza_list)+len(pizza_sizes)+len(special_paladin_pizzas)+1} - {len(pizza_list)+len(pizza_sizes)+len(special_paladin_pizzas)+len(extra_toppings)}") print() # --- Special pizzas --- want_special_pizzas = string_check("Would you like a special pizza? ", yes_no_list) if want_special_pizzas == "yes": while True: special_num = input( f"Choose special pizza number ({len(pizza_list) + len(pizza_sizes) + 1}-" f"{len(pizza_list) + len(pizza_sizes) + len(special_paladin_pizzas)}): ").strip() if special_num.lower() == "xxx": break if special_num.isdigit(): special_num = int(special_num) if len(pizza_list) + len(pizza_sizes) + 1 <= special_num <= len(pizza_list) + len(pizza_sizes) + len(special_paladin_pizzas): special_index = special_num - (len(pizza_list) + len(pizza_sizes)) special_name = special_paladin_pizzas[special_index - 1] special_price = special_prices[special_index - 1] print(f"You chose {special_name}, this costs {currency(special_price)}") order_summary.append((f"Special: {special_name}", special_price)) break print(f"Please choose a number between {len(pizza_list)+len(pizza_sizes)+1} - {len(pizza_list)+len(pizza_sizes)+len(special_paladin_pizzas)}") pizzas_sold += 1 if pizzas_sold >= MAX_PIZZAS: print(f"You've reached the maximum of {MAX_PIZZAS} pizzas.") break print() another_pizza = string_check("Would you like another pizza? ", yes_no_list) if another_pizza == "no": break print() # payment method payment_method = string_check("Please choose a payment: ", payment_ans, 1) print(f"You chose {payment_method}") print() # Prints out the Receipt for the customer make_statement(f"{name}'s Order Receipt", decoration="📜") # Customer contact info print(f"Customer Name: {name}") print(f"Phone Number: {phone_number}") if delivery_choice == "delivery": print(f"Address: {address}") print("------------------------------------") # Order details subtotal = 0 for item, price in order_summary: print(f"{item:<30} {currency(price)}") subtotal += price # delivery fee if delivery_choice == "delivery": print(f"{'Delivery Fee':<30} {currency(DELIVERY_FEE)}") subtotal += DELIVERY_FEE # Credit surcharge surcharge = 0 if payment_method == "credit": surcharge = subtotal * CREDIT_SURCHARGE print(f"{'Credit Card Surcharge (2.5%)':<30} {currency(surcharge)}") total = subtotal + surcharge print("------------------------------------") print(f"{'Subtotal':<30} {currency(subtotal)}") print(f"{'Total':<30} {currency(total)}") print("------------------------------------") # Confirmed order confirm_order = string_check("Would you like to confirm this order? (yes/no): ", yes_no_list) if confirm_order == "yes": # create a file to hold in the data file_name = "Pizza_data_experiment" write_to = "{}.txt".format(file_name) text_file = open(write_to, "w+") # strings to write to file... heading = "=== Pizza Test ===\n" user_information = f"{name}, {payment_method}, {phone_number}," user_order = "" pickup_or_delivery = f"{address}" # list of strings to_write = [heading, user_information, pickup_or_delivery] # write the item to file for item in to_write: text_file.write(item) text_file.write("\n") print() make_statement("Thank you for ordering at Pizza Paladin", decoration="🍕") print("We hope you come back again!!") else: print("Order cancelled.") print() # Ask if they want another order or exit another_order = string_check("Would you like to place another order? ", yes_no_list) if another_order == "no": print("Goodbye! Thanks for visiting Pizza Paladin!") break