import pandas # Functions go here def int_check(question, low, high): """Checks user enter an integer """ error = f"Oops - please enter a number between {low} and {high} " while True: try: response = int(input(question)) if response >= low and response <= high: return response else: print(error) except ValueError: print(error) def make_statement(statement, decoration, lines=1): """Creates headings (3 lines), subheadings (2lines) and emphasised text / mini-headings (1 line). Only use emoji for single line statements""" 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) # currency formatting function def currency(x): """Format numbers as currency ($#.##)""" return "${:.2f}".format(x) def string_check(question, valid_answers=('yes', 'no'), 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_answers: # check if the response is the entire word if response == item: return item # check if it's the 'n' letters elif response == item[:num_letters]: return item print(f"Please choose an option from {valid_answers}") 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 instructions(): make_statement("Instructions", "â„šī¸") print(''' For each Customer enter ... - Their name - Their age - The payment method (cash / credit) The program will record the burgers chosen and calculate the order cost, and surcharge. Once you have either bought 5 burgers, the program will display the order information and write the data to a text file (receipt). ''') # Burger ordered list user_burger_choice = [] user_burger_choice_cost = [] order_dict = { 'Item': user_burger_choice, 'Price': user_burger_choice_cost, } # Variables MAX_BURGERS = 5 burgers_sold = 0 # burger lists 1 burger_items = ["Cheese", "Beef", "Chicken", "BBQ", "Veggie", "Bacon Deluxe", "Spicy Chicken", "Pesto", "Hawaiian", "Double Beef", ] burger_cost = [7.50] * 10 burger_dict_1 = { 'Burger': burger_items, 'Price': burger_cost, } # burger list 2 special_burger = ["Dessert Burger", "Butter Chicken Burger"] special_burger_cost = [6.50, 8.50] burger_dict_2 = { 'Special Burger': special_burger, 'Price': special_burger_cost, } # burger sizes burger_size = ["Small", "Medium", "Large"] burger_size_cost = [2.50, 3.50, 4.50] burger_dict_3 = { 'Sizes': burger_size, 'Price': burger_size_cost, } # create dataframe/s burger_frame = pandas.DataFrame(burger_dict_1) burger_frame.index = burger_frame.index + 1 burger_frame_2 = pandas.DataFrame(burger_dict_2) burger_frame_2.index = burger_frame_2.index + 1 burger_frame_3 = pandas.DataFrame(burger_dict_3) burger_frame_3.index = burger_frame_3.index + 1 # Currency Formatting (uses currency function) add_dollars = ['Price'] for var_item in add_dollars: burger_frame[var_item] = burger_frame[var_item].apply(currency) burger_frame_2[var_item] = burger_frame_2[var_item].apply(currency) burger_frame_3[var_item] = burger_frame_3[var_item].apply(currency) # Main routine goes here make_statement(statement="Bun Bro's", decoration="🍔") print() want_instructions = string_check("Do you want to see the instructions? ") if want_instructions == "yes": instructions() print(burger_frame) make_statement(statement="", decoration="----") print(burger_frame_2) make_statement(statement="", decoration="----") print(burger_frame_3) # initialise variables / non-default options for string checker payment_ans = ('cash', 'credit') print() # ask user for their name name = input("Name: ") # replace with call to 'not blank' function! # Ask for their age and check it's between 12 and 120 age = int_check("Age: ", 12, 120) # Output error message / success message if age < 12: print(f"{name} is too young") elif age > 120: print(f"{name} is too old") else: pass # ask user for payment method (cash / credit / ca / cr) pay_method = string_check("Payment method: ", payment_ans, 2) print(f"{name} is ordering ({pay_method})") # Ordering system # Get burger choice while burgers_sold < MAX_BURGERS: print() typeofburger = int_check("Would you like a general burger or special burger?(1 for general, 2 for special)", 1, 2) if typeofburger == 1: print("You chose general burger") burger_choice = int_check("Enter burger order number(1-10): ", 1, 10) print() print(f"-{burger_items[burger_choice - 1]}") user_burger_choice.append(burger_items[burger_choice - 1]) user_burger_choice_cost.append(7.5) print() burgers_sold += 1 print(f"Burgers ordered: {burgers_sold}/{MAX_BURGERS}") print() elif typeofburger == 2: print("You chose special burger") burger_choice = int_check("Enter special burger number(1-2): ", 1, 2) print() print(f"{special_burger[burger_choice - 1]}") user_burger_choice.append(special_burger[burger_choice - 1]) user_burger_choice_cost.append(special_burger_cost[burger_choice - 1]) print() burgers_sold += 1 print(f"Burgers ordered: {burgers_sold}/{MAX_BURGERS}") print() if burgers_sold < MAX_BURGERS: want_burger = string_check("Would you like another burger? ") print() if want_burger == "no": print("Your order will now be processed.") print(f"Burgers ordered: {burgers_sold}/{MAX_BURGERS}") print(f"Your burgers ") break else: continue if burgers_sold == MAX_BURGERS: print("You have reached the max amount of burgers!!!") # user order print() order_frame = pandas.DataFrame(order_dict) order_frame.index = order_frame.index + 1 for items in add_dollars: order_frame[items] = order_frame[items].apply(currency) print() print(order_frame) print() Order_cost = sum(user_burger_choice_cost) print(f"Total cost: {currency(Order_cost)}")