import pandas # Functions go here def int_check(question): """Checks user enter an integer """ error = "Oops - please enter an integer. " while True: try: response = int(input(question)) return response except ValueError: print(error) def make_statement(statement, decoration, lines=1): """Creates headings (3 lines), subheadings (2 lines) 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: if response == item or 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). ''') # Main program menu (matches main Bun Bro's program) # Regular burgers burger_items = [ "Cheeseburger", "Bacon Burger", "Chicken Burger", "Veggie Burger", "Double Beef", "BBQ Burger", "Mushroom Swiss", "Fish Burger", "Spicy Jalapeño", "Classic Burger" ] burger_cost = [7.50] * 10 burger_dict_1 = { 'Burger': burger_items, 'Price': burger_cost, } # Special burgers special_burgers = ["Lamb Burger", "Pulled Pork Burger"] special_burger_cost = [8.50, 9.50] burger_dict_2 = { 'Special Burger': special_burgers, '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 DataFrames 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 + 11 burger_frame_3 = pandas.DataFrame(burger_dict_3) burger_frame_3.index = burger_frame_3.index + 1 # Format currency 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 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 = not_blank("Name: ") # Ask for their age and check it's between 12 and 120 age = int_check("Age: ") 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) pay_method = string_check("Payment method: ", payment_ans, 2) print(f"{name} is ordering ({pay_method})")