import pandas from datetime import date import math import numpy as np # Functions go here def make_statement(statement, decoration): """Emphasis headings by adding decoration at the start and end""" return f"{decoration * 3} {statement} {decoration * 3}" def yes_no_check(question): while True: response = input(question).lower() if response in ["yes", "y"]: return "yes" elif response in ["no", "n"]: return "no" else: print("Please enter yes / no\n") def instructions(): print(make_statement("Instructions", "โ•")) print(''' For each burger wanted type... - The burgers name - How many burgers - The size - Extra toppings The program will record the amount of burgers, the types of burgers, the size of burgers, the extra toppings, and the cost. This program will also ask for the following... - Your Name - Phone Number - Address You can buy 3 burgers per order with a maximum of 5 burgers overall. Once you have either bought 5 burgers or wish to finish your order. the program will display the information on your burger. Enter corresponding number for items on menu to purchase. If buying with credit ad a surcharge of 2%. ''') def string_check(question, valid_answer, num_letters=1): """Checks that users enter the full word or the 'n' letter/s of a word from a list of valid responses""" while True: response = input(question).lower() for item in valid_answer: if response == item: return item elif response == item[:num_letters]: return item print(f"Please choose an option from {valid_answer}") def menu(): print(make_statement("Menu", "๐Ÿ“ƒ")) print(''' Burgers: 1. Chicken 2. Bacon 3. Cheese 4. Bacon and Egg 5. Vegan Extra Toppings: 1. Cheese 2. Ham 3. Pineapple 4. Bacon 5. Onion All Extra Toppings $1 ''') 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 num_check(question, low, high): """Checks users enter an integer between low and high""" while True: error = f"Enter a number between {low} and {high}" try: response = int(input(question)) if low <= response <= high: return response else: print(error) except ValueError: print(error) def currency(x): """Formats numbers as currency ($#.##)""" return "${:.2f}".format(x) def round_up(amount, round_val): """Rounds amount to desired whole number""" return int(math.ceil(amount / round_val)) * round_val def get_valid_phone(): while True: phone = input("Enter your phone number (NZ only): ").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() if len(address) < 3: print("Address is too short, please enter a valid address") continue if not any(char.isdigit() for char in address): print("Address must include a number (e.g. house number).") continue if not any(char.isalpha() for char in address): print("Address must include letters (e.g. street name).") continue return address 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 } def get_payment_method(): """Ask the customer how they want to pay (cash or credit).""" return string_check("Would you like to pay with cash or credit? ", ["cash", "credit"], 1) # ---------------- Main Ordering System ---------------- def order(total_burger_made, total_cost_burger): customer = get_customer_details() if customer["delivery_method"] == "delivery": delivery_fee = 3.00 print(f"A delivery fee of ${delivery_fee:.2f} has been added to your order.") total_cost_burger += delivery_fee cust_burger, cust_burger_size, cust_burger_cost, cust_extra_toppings, cust_burger_amount = [], [], [], [], [] while True: max_remaining = MAX_BURGERS - total_burger_made max_allowed = min(MAX_PER_ORDER, max_remaining) burger_type = num_check("Which burger? (1-5): ", 1, 5) quantity_made = num_check(f"Quantity being made (max {max_allowed}): ", 1, max_allowed) total_burger_made += quantity_made cust_burger.append(burger_list[burger_type - 1]) cust_burger_amount.append(quantity_made) print(f"You have purchased {quantity_made} {burger_list[burger_type - 1]} burgers!") print("Sizes and Prices: Large ($10) Medium ($7.50) Small ($5)") burger_size = string_check("Enter the size: ", size_options) if burger_size == "large": burger_price = 10 elif burger_size == "medium": burger_price = 7.50 else: burger_price = 5 cust_burger_size.append(burger_size) extra_toppings = yes_no_check("Would you like extra toppings on your burger? ") if extra_toppings == "yes": ask_extra_toppings = num_check("Which extra toppings? (1-5): ", 1, 5) print(f"You have purchased {toppings_list[ask_extra_toppings - 1]}!") burger_price += 1 cust_extra_toppings.append(toppings_list[ask_extra_toppings - 1]) else: print("No extra toppings will be added to your burger.") cust_extra_toppings.append("None") single_burger_cost = burger_price * quantity_made total_cost_burger += single_burger_cost cust_burger_cost.append(single_burger_cost) cust_order_dict = { 'Burger': cust_burger, 'Burger Amount': cust_burger_amount, 'Burger Size': cust_burger_size, 'Extra Toppings': cust_extra_toppings, 'Cost': cust_burger_cost } cust_order_frame = pandas.DataFrame(cust_order_dict) cust_order_frame.index = np.arange(1, len(cust_order_frame) + 1) print(cust_order_frame) print(f"You have spent a total of ${total_cost_burger:.2f}") if total_burger_made >= MAX_BURGERS: print("Max burgers bought!") break print(f"You currently have {total_burger_made} burgers, you can buy {MAX_BURGERS - total_burger_made} more!") another_burger = yes_no_check("Would you like another flavour of burger? ") if another_burger == "no": break # --- Confirmation --- print(make_statement("ORDER SUMMARY", "๐Ÿงพ")) print(f"Customer: {customer['name']}") print(f"Phone: {customer['phone']}") if customer['delivery_method'] == "delivery": print(f"Delivery Address: {customer['address']}") else: print("Pickup order") print() print(cust_order_frame) print(f"TOTAL COST: ${total_cost_burger:.2f}") print() confirm = yes_no_check("Do you want to confirm this order? ") if confirm == "yes": payment_method = get_payment_method() if payment_method == "credit": surcharge = total_cost_burger * 0.02 total_cost_burger += surcharge print(f"A 2% credit surcharge of ${surcharge:.2f} has been added.") print(make_statement("FINAL RECEIPT", "๐Ÿงพ")) print(f"Customer: {customer['name']}") print(f"Phone: {customer['phone']}") if customer['delivery_method'] == "delivery": print(f"Delivery Address: {customer['address']}") else: print("Pickup order") print() print(cust_order_frame) print(f"TOTAL COST: ${total_cost_burger:.2f}") print(f"Payment Method: {payment_method.capitalize()}") print(make_statement("Thank you for shopping at Isaacs Burgers!", "๐Ÿ•")) else: print(make_statement("ORDER CANCELLED", "โŒ")) # ---------------- Program Starts ---------------- MAX_BURGERS = 5 MAX_PER_ORDER = 3 total_burger_made = 0 total_cost_burger = 0 size_options = ["large", "medium", "small"] burger_list = ["Chicken", "Bacon", "Cheese", "Bacon and Egg", "Vegan" ] toppings_list = ["Cheese", "Ham", "Pineapple", "Bacon", "Onion"] print(make_statement("Isaacs Burger Shop", "๐Ÿ•")) print() want_instructions = yes_no_check("Do you want to see the instructions? ") if want_instructions == "yes": instructions() print() while True: want_menu = yes_no_check("Do you want to see the menu? ") if want_menu == "yes": menu() print() order(total_burger_made, total_cost_burger) another_order = yes_no_check("Would you like to order again?") if another_order == "yes": continue if another_order == "no": break print("Thank you for shopping at Isaacs Burgers")