import pandas # Functions def make_statement(statement, decoration, lines=1): """Creates headings (3 lines), subheadings (2 lines) and emphasised text (1 line)""" 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 string_check(question, valid_answers=('yes', 'no'), num_letters=1): """Checks input is in a list or matches first 'n' letters""" while True: response = input(question).lower() for item in valid_answers: if response == item or response == item[:num_letters]: return item print(f"Please choose an option from {valid_answers}") def instructions(): make_statement("Instructions", "â„šī¸") print(''' For each order enter: - Their name - Their age - The payment method (cash / credit) Program will record burger sales and calculate the order cost. Once you have either sold all 5 burgers or entered the exit code ('xxx'), the program will display the receipt and write the data to a text file. ''') def not_blank(question): """Ensures input 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): """Ensures user enters an integer or 'xxx'""" error = "Oops - please enter an integer between the given range." while True: 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) # burger ordered list user_burger_choice = [] user_burger_cost = [] order_dict = { 'Item': user_burger_choice, 'Price': user_burger_cost } # Program starts make_statement("Burger Borough", "🍔") print() want_instructions = string_check("Do you want to see the instructions? ") if want_instructions == "yes": instructions() # Constants MAX_BURGERS = 5 burgers_sold = 0 payment_ans = ('cash', 'credit') CREDIT_SURCHARGE = 0.05 # Burger types and prices burger_types = ["Cheeseburger", "Pepperoni Burger", "Ham & Cheese Burger", "BBQ Burger", "Veggie Burger", "Meat-lovers Burger", "Spicy Chicken Burger", "Pesto Burger", "Hawaiian Burger", "Classic Burger"] special_burgers = ["Dessert Burger", "Butter Chicken Burger"] burger_cost = [6.50] * 10 special_price = [6.75, 7] # Combined lists all_burgers = burger_types + special_burgers all_prices = burger_cost + special_price # Create and format menu DataFrames burger_dict = {'Burger': burger_types, 'Price': burger_cost} special_dict = {'Special Burger': special_burgers, 'Price': special_price} burger_frame = pandas.DataFrame(burger_dict) burger_frame.index = burger_frame.index + 1 burger_frame['Price'] = burger_frame['Price'].apply(currency) special_frame = pandas.DataFrame(special_dict) special_frame.index = special_frame.index + 1 special_frame['Price'] = special_frame['Price'].apply(currency) # Show menu once make_statement("Burger Menu", "🍔") print(burger_frame) make_statement("", "----") print(special_frame) # Get customer name and payment method once print() name = not_blank("Name (or 'xxx' to quit): ") if name == "xxx": print("Program ended") exit() pay_method = string_check("Payment method (5% surcharge for credit): ", payment_ans, 2) if pay_method == "cash": surcharge_rate = 0 else: surcharge_rate = CREDIT_SURCHARGE print() print(f"{name} is ordering with {pay_method}") # Order loop while burgers_sold < MAX_BURGERS: print() type_of_burger = int_check("Would you like regular burger (1) or special burger (2)?", 1, 2) if type_of_burger == 1: burger_choice = int_check("Enter burger order number (1-10)", 1, 10) print() print(f"-{burger_types[burger_choice - 1]}") user_burger_choice.append(burger_types[burger_choice - 1]) user_burger_cost.append(6.5) print() burgers_sold += 1 elif type_of_burger == 2: burger_choice = int_check("Enter special burger order number (1-2)", 1, 2) print() print(f"-{special_burgers[burger_choice - 1]}") user_burger_choice.append(special_burgers[burger_choice - 1]) user_burger_cost.append(special_price[burger_choice - 1]) print() burgers_sold += 1 if burgers_sold < MAX_BURGERS: like_burger = string_check("Would you like another burger? ") print(f"{burgers_sold}/{MAX_BURGERS} Burgers Sold") if like_burger == "no": print("Thanks for your order!") break continue # user order receipt order_frame = pandas.DataFrame(order_dict) order_frame.index = order_frame.index + 1 order_frame['Price'] = order_frame['Price'].apply(currency) print(order_frame) print() Order_cost = sum(user_burger_cost) surcharge = Order_cost * surcharge_rate total_due = Order_cost + surcharge print(f"Subtotal: {currency(Order_cost)}") print(f"Surcharge: {currency(surcharge)}") print(f"Total Due: {currency(total_due)}") print("Program ended")