# Functions go here import pandas # Importing numpy package import numpy as np def string_check(question, valid_list=('yes', 'no'), num_letters=1): """Checks that users enter the full word or the first 'n' letters from a list""" while True: response = input(question).strip().lower() for item in valid_list: item_low = item.lower() if response == item_low: return item elif response == item_low[:num_letters]: return item print(f"Please choose an option from {valid_list}") def instructions(): print("Pizza Paladin Instructions," "ℹ️") print(""" The program will record the users data that they entered, then proceed to the main menu of what Pizza Paladin offers. Once you have ordered your pizza (up to 5 maximum allowed), or entered the exit code (‘xxx’), the program will display the receipt information regarding the customers order, writing the data to a text file. The program proceeds by asking would you like to pick-up or deliver the pizza to your address. For each customer should enter ... ------ (IF PICK-UP WAS CHOSEN) ------ - Their name - Phone number - The payment method (cash / credit) ------ (IF DELIVERY WAS CHOSEN) ------ - Their name - Phone number - Address - The payment method (cash / credit) The program will record the users data that they entered, then proceed to the order by printing a receipt """) def make_statement(statement, decoration, lines=1): 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 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 int_check(question, low, high): """Checks users enter an integer that is more than zero (or the 'xxx' exit code)""" error = f"Oops - please enter a number between {low} and {high}." while True: response = input(question) if response == "xxx": return response try: response = int(input(response)) if response >= low or response <= high: return response else: print(error) except ValueError: print(error) def currency(x): """Formats numbers as currency ($#.##)""" return "${:.2f}".format(x) # Variables MAX_PIZZAS = 5 pizzas_sold = 0 payment_ans = ('cash', 'credit') yes_no_list = ('yes', 'no') # Credit extra charge is 2.5% CREDIT_SURCHARGE = 0.025 # Delivery fee delivery_fee = 20 make_statement(statement="Welcome To Pizza Paladin!", decoration="🍕") print() want_instructions = string_check("Do you want to see the instructions? ") if want_instructions == "yes": instructions() print() pizza_list = ["Pepperoni", "Hawaiian", "Margherita", "BBQ Chicken", "Meat Lovers", "Cheese Pizza", "Veggie Pizza", "Kebab Pizza", "Spaghetti Pizza", "Smash Burger"] special_paladin_pizzas = ["Sushi Pizza", "S'more Pizza", "-", "------- Extra Toppings"] extra_toppings = ["Extra cheese", "Mushrooms", "Onions", "Pineapple", "Green Peppers"] pizza_sizes = ["Small", "Medium", "Large"] pizza_cost = [8.30, 8.30, 8.30, 8.30, 8.30, 8.30, 8.30, 8.30, 8.30, 8.30] special_pizza_costs = [6.70, 6.40] extra_topping_costs = [1.80, 1.20, 1.20, 1.30, 1.10] pizza_sizes_cost = [2.70, 3.50, 4.20] pizza_paladin_dict = { 'Pizza': pizza_list, 'Price': pizza_cost } pizza_paladin_menu = pandas.DataFrame(pizza_paladin_dict) # Rearranging index pizza_paladin_menu.index = np.arange(1, len(pizza_paladin_menu) + 1) # Currency Formatting add_dollars = ['Price'] for var_item in add_dollars: pizza_paladin_menu[var_item] = pizza_paladin_menu[var_item].apply(currency) # Main routine starts here make_statement(statement="Pizza Paladin Main Menu", decoration="🍕") make_statement(statement="--------------------------------", decoration="") print(pizza_paladin_menu) print() # Ask the customers name print() name = not_blank("Name (or 'xxx' to quit): ") print() if name == "xxx": print("Order cancelled. Hope you come back and order a pizza from Pizza Paladin!") exit() # Pizza order tracking order_summary = [] # A while loop that enables the customer to order x/5 amount of pizza with questions that are looped while pizzas_sold < MAX_PIZZAS: yes_no_list = ['yes', 'no'] pizza_sizes = ['small', 'medium', 'large'] gourmet_options = ["Pepperoni", "Hawaiian", "Margherita", "BBQ Chicken", "Meat Lovers", "Cheese Pizza", "Veggie Pizza", "Kebab Pizza", "Spaghetti Pizza", "Smash Burger"] special_pizzas = ["Sushi Pizza", "S'more Pizza"] extra_toppings = ["Extra cheese", "Mushrooms", "Onions", "Pineapple", "Green Peppers"] choose_pizza = int_check("Choose a gourmet pizza (or type 'xxx' to quit): ", 1, 10) if choose_pizza == "xxx": print("Exiting pizza ordering...") break print() chosen_size = string_check("What size of the pizza would you like? ", pizza_sizes, 2) print(f"You chose {chosen_size}") print() # adds the pizza to a summary list if choose_pizza.title() in pizza_list: pizza_index = pizza_list.index(choose_pizza.title()) base_price = pizza_cost[pizza_index] else: print(f"{choose_pizza} not found in the menu.") continue # order calculations for summary size_index = pizza_sizes.index(chosen_size.lower()) size_price = pizza_sizes_cost[size_index] pizza_total = base_price + size_price order_summary.append((f"{choose_pizza.title()} ({chosen_size.title()})", pizza_total)) extra_toppings_pizza = string_check("Would you like extra toppings? ", yes_no_list, 3) if extra_toppings_pizza == "yes": extra_toppings_choose = string_check("Extra toppings: ", extra_toppings, 99) topping_index = pizza_paladin_dict['Pizza'].index(extra_toppings_choose.title()) topping_price = pizza_cost[topping_index] order_summary.append((f"Extra: {extra_toppings_choose.title()}", topping_price)) print() want_special_pizzas = string_check("We have limited edition special pizzas, are you interested? ", yes_no_list, 4) if want_special_pizzas == "yes": special_pizzas_choose = string_check("What type of special pizza would you like? ", special_pizzas, 99) special_index = pizza_paladin_dict['Pizza'].index(special_pizzas_choose.title()) special_price = pizza_cost[special_index] order_summary.append((f"Special: {special_pizzas_choose.title()}", special_price)) # adds a threshold into the 5 maximum ordered pizza, # so everytime the user enters yes for another pizza, it adds onto the threshold pizzas_sold += 1 # if users ordered a max of 5 pizzas, the program exits moving onto the next question if pizzas_sold >= MAX_PIZZAS: print(f"You've reached the maximum of {MAX_PIZZAS} pizzas.") break # tells the customers how many pizzas they have ordered print() print(f"Pizza's Ordered: {pizzas_sold}/{MAX_PIZZAS}") print() another_pizza = string_check("Would you like another pizza? 🍕 ", yes_no_list, 4) if another_pizza == "no": break print(f"Your order will now be processed!") print() # payment method payment_method = string_check("Please choose a payment: ", payment_ans, 1) print(f"You chose {payment_method}") print() # Prints out the Receipt for the customer make_statement(f"{name}'s Order Receipt", decoration="📜") subtotal = 0 for item, price in order_summary: print(f"{item:<30} {currency(price)}") subtotal += price surcharge = 0 if payment_method == "credit": surcharge = subtotal * CREDIT_SURCHARGE print(f"{'Credit Card Surcharge (2.5%)':<30} {currency(surcharge)}") total = subtotal + surcharge print(f"{'Subtotal':<30} {currency(subtotal)}") print(f"{'Total':<30} {currency(total)}") print(f"------------------------------------") # Phone Number phone_number = not_blank("What is your phone number? ") # Deliver or Pick up pizza print() pizza_delivered_pickup = ["Deliver", "Pick Up"] deliver_options = "You can either: Deliver or Pick Up" print(deliver_options) print() get_pizza = string_check("Choose how you would like to get the pizza, refer to the above: ", pizza_delivered_pickup, 5) print() print(f"You chose to {get_pizza} the pizza") print() if get_pizza == "Deliver": address = not_blank("Please enter your address: ") print() print(f"There is a delivery fee of ${delivery_fee}") print(f"Your pizza will be delivered to {address} in 15 minutes! ") elif get_pizza == "Pick Up": print(f"Your Pizza will be ready to pick up in 15 minutes!") print() # create a file to hold in the data file_name = "Pizza_data_experiment" write_to = "{}.txt".format(file_name) text_file = open(write_to, "w+") # strings to write to file... heading = "=== Pizza Test ===\n" user_information = f"{name}, {payment_method}, {phone_number}," user_order = "" pickup_or_delivery = f"{address}" # list of strings to_write = [heading, user_information, pickup_or_delivery] # print the output for item in to_write: print(item) # write the item to file for item in to_write: text_file.write(item) text_file.write("\n") print() make_statement("Thank you for ordering at Pizza Paladin", decoration="🍕") print(f"We hope you come back again!!")