import pandas as pd def int_checker(question, low, high): """ Prompt the user for an integer input between 'low' and 'high'. If the input is invalid, keep prompting until a valid input is provided. """ while True: error = f"Enter a number between {low} and {high} or 'd' for done." to_check = input(question).lower() if to_check in ["d", "done"]: return "d" if to_check.isdigit(): user_response = int(to_check) if low <= user_response <= high: return user_response else: print(error) else: print(error) def string_checker(question, valid_ans): """ Prompt the user for a string input and check if it matches one of the valid answers. Allows for shortcuts (first letter) to be used for valid responses. """ shortcuts = {k[0]: k for k in valid_ans} while True: user_response = input(question).strip().lower() if user_response in shortcuts: return shortcuts[user_response] elif user_response in valid_ans: return user_response print(f"Enter a valid response from {valid_ans}") def cash_credit(question): """ Prompt the user for a payment method and ensure it's valid. """ valid_responses = {"c": "cash", "cr": "credit"} while True: response = input(question).lower() if response in valid_responses: return valid_responses[response] elif response in ["cash", "credit"]: return response print("Please choose a valid payment method: 'c' or 'cash' for cash, 'cr' or 'credit' for credit.") def history(): """ Display the history of the burger shop. """ print('''Welcome to the home of gourmet burgers! Since 1990, our family-owned Whanau Burger has been serving up delicious, handcrafted burgers with fresh ingredients. Founded by burger enthusiasts Luca and Sofia Di Napoli, Whanau Burger brings a unique blend of traditional and contemporary flavors to your plate. ''') def display_menu(): """ Display the menu of available toppings and burger sizes. """ gourmet_toppings_data = { "Item": [ "13: Premium Bacon", "14: Fried Egg", "15: Avocado", "16: Blue Cheese", "17: Grilled Mushrooms", "18: Vege Patty", "19: Angus Patty" ], "Cost": [ "2.50", "1.50", "2.00", "2.00", "1.50", "3.00", "4.50" ] } regular_menu_data = { "Item": [ "1: Lettuce", "2: Tomato", "3: Pickles", "4: Onion", "5: American Cheese", "6: Cheddar Cheese", "7: Swiss Cheese", "8: BBQ Sauce", "9: Ketchup", "10: Mustard", "11: Mayo", "12: Grilled Onion" ], "Cost": [ "Free", "Free", "Free", "Free", "1.00", "1.00", "1.50", "0.50", "0.50", "0.50", "0.50", "1.00" ] } df_gourmet_toppings = pd.DataFrame(gourmet_toppings_data) df_regular_menu = pd.DataFrame(regular_menu_data) print("<--------------- Menu --------------->") print("Gourmet Toppings:") print(df_gourmet_toppings.to_string(index=False, formatters={'Item': '{:<30}'.format, 'Cost': '${:>5}'.format})) print("Burger Toppings:") print(df_regular_menu.to_string(index=False, formatters={'Item': '{:<30}'.format, 'Cost': '${:>5}'.format})) print("\n Small | Medium | Large |") print(" $5 | $7 | $9 |") print(" ------|--------|-------|") print( "Note: Lettuce, Tomato, and Pickles are free. Other toppings come with additional cost.\n" "Note: Please only enter one topping at a time\n") def get_size_cost(size_option, size_prices): """ Get the size and cost of the burger. """ size = string_checker("Choose a burger size (s/m/l or small/medium/large): ", size_option) return size, size_prices[size] def get_toppings(toppings_menu): """ Get the selected toppings and their total cost. """ toppings = [] total_topping_cost = 0.0 while True: topping = int_checker("Choose a topping (1-19) or type 'd' for done: ", 1, 19) if topping == 'd': break if topping in toppings_menu: toppings.append(topping) topping_cost = toppings_menu[topping]['cost'] total_topping_cost += topping_cost print(f"{toppings_menu[topping]['name']} added. Total topping cost: ${total_topping_cost:.2f}") else: print("Invalid topping number. Please choose a number from 1 to 19.") return toppings, total_topping_cost def order_one_burger(burger_number, size_option, size_prices, toppings_menu): """ Order one burger with specified size and toppings. """ display_menu() print(f"\nOrdering burger {burger_number}...") size, size_cost = get_size_cost(size_option, size_prices) toppings, topping_cost = get_toppings(toppings_menu) total_cost = size_cost + topping_cost return size, size_cost, toppings, total_cost def order_multiple_burgers(size_option, size_prices, toppings_menu): """ Order multiple burgers, with each burger's details and total cost. """ total_cost = 0 burger_details = [] burger_number = 1 while True: size, size_cost, toppings, burger_total_cost = order_one_burger(burger_number, size_option, size_prices, toppings_menu) burger_summary = f"Burger {burger_number} - Size: {size.capitalize()} (${size_cost})" if toppings: burger_summary += "\n Toppings:" for topping in toppings: burger_summary += f"\n - {toppings_menu[topping]['name']}: ${toppings_menu[topping]['cost']}" burger_summary += f"\n Total for this burger: ${burger_total_cost:.2f}" print(burger_summary) burger_details.append(burger_summary) total_cost += burger_total_cost order_more = string_checker("Order another burger? (y/n or yes/no): ", ["y", "n", "yes", "no"]) if order_more in ["n", "no"]: break burger_number += 1 return burger_details, total_cost def not_blank(question, allow_numeric_only=False): """ Prompt for a non-blank input, optionally allowing numeric-only input. """ error = "Enter a name." while True: user_input = input(question).strip() if allow_numeric_only: if user_input.isdigit(): return user_input else: print("Enter a valid numeric phone number.") elif user_input: return user_input else: print(error) def confirm_order(burger_details, total_cost): """ Ask the user to confirm the order and handle confirmation. """ print("\nOrder Summary:") for detail in burger_details: print(detail) print(f"\nTotal cost for all burgers: ${total_cost:.2f}") confirmation = string_checker("Do you want to confirm this order? (y/n or yes/no): ", ["y", "n", "yes", "no"]) if confirmation in ["n", "no"]: print("Would you like to place a new order?") new_order = string_checker("Start a new order? (y/n or yes/no): ", ["y", "n", "yes", "no"]) if new_order in ["y", "yes"]: order_burger() else: print("Thank you for visiting Whanau Burger. Have a great day!") exit() else: payment_method = cash_credit("Choose a payment method (c/cr or cash/credit): ") print(f"Payment method: {payment_method.capitalize()}") def order_burger(): """ Main function to handle the burger ordering process. """ print("<--- Welcome to Whanau Burger --->") print("In this order system, you will create a custom burger. 🍔") want_history = string_checker("\nLearn about the history of Whanau Burger? (y/n or yes/no): ", ["y", "n", "yes", "no"]) if want_history in ["y", "yes"]: history() want_order = string_checker("Order delivery or pick up? (d/p or delivery/pick up): ", ["d", "p", "delivery", "pick up"]) if want_order in ["d", "delivery"]: print("\n$10 surcharge for delivery.") user_name = not_blank("Enter your name: ") phone_number = not_blank("Enter your phone number: ", allow_numeric_only=True) address = not_blank("Enter your address: ") else: print("Our address is:\n565 Maunganui Road, Mount Maunganui 3116.") user_name = not_blank("Enter your name: ") phone_number = not_blank("Enter your phone number: ", allow_numeric_only=True) want_instructions = string_checker("Read the instructions? (y/n or yes/no): ", ["y", "n", "yes", "no"]) if want_instructions in ["y", "yes"]: print("\nYou will see a menu with options for burger toppings and gourmet toppings." "\nSelect toppings by entering the corresponding number. Type 'd' when finished.\n") else: print("No instructions will be displayed.\n") size_option = {"s": "small", "m": "medium", "l": "large", "small": "small", "medium": "medium", "large": "large"} size_prices = {"small": 5, "medium": 7, "large": 9} toppings_menu = { 1: {'name': 'Lettuce', 'cost': 0}, 2: {'name': 'Tomato', 'cost': 0}, 3: {'name': 'Pickles', 'cost': 0}, 4: {'name': 'Onion', 'cost': 0}, 5: {'name': 'American Cheese', 'cost': 1.00}, 6: {'name': 'Cheddar Cheese', 'cost': 1.00}, 7: {'name': 'Swiss Cheese', 'cost': 1.50}, 8: {'name': 'BBQ Sauce', 'cost': 0.50}, 9: {'name': 'Ketchup', 'cost': 0.50}, 10: {'name': 'Mustard', 'cost': 0.50}, 11: {'name': 'Mayo', 'cost': 0.50}, 12: {'name': 'Grilled Onion', 'cost': 1.00}, 13: {'name': 'Premium Bacon', 'cost': 2.50}, 14: {'name': 'Fried Egg', 'cost': 1.50}, 15: {'name': 'Avocado', 'cost': 2.00}, 16: {'name': 'Blue Cheese', 'cost': 2.00}, 17: {'name': 'Grilled Mushrooms', 'cost': 1.50}, 18: {'name': 'Vege Patty', 'cost': 3.00}, 19: {'name': 'Angus Patty', 'cost': 4.50} } burger_details, total_cost = order_multiple_burgers(size_option, size_prices, toppings_menu) confirm_order(burger_details, total_cost) if __name__ == "__main__": order_burger()