import pandas import numpy as np # Functions go here def make_statement(statement, decoration): """Emphasizes heading by adding decoration at the start and end""" print(f"{decoration * 3}: {statement} {decoration * 3} ") 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 range 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 instructions(): print(''' For each ticket holder enter ... - Their name - Their age - The payment method (cash / credit) The program will record the ticket sale and calculate the ticket cost (and the profit). Once you have either sold all of the tickets or entered the exit code ('xxx'), the program will display the ticket sales information and write the data to a text file. It will also choose one lucky ticket holder who wins the draw (their ticket is free). ''') def int_check(question, low, high): """Checks users enter an integer""" error = f"please enter between {low} or {high}." while True: try: # Return the response if it's an integer response = int(input(question)) if response >= low and response <= high: return response else: print(error) except ValueError: print(error) # Variables number_of_pizzas = 0 pizza = ["Pepperoni", "Hawaiian", "Meat Lovers",] pizza_prices = [13, 12, 15,] pizza_menu = { 'Pizza': pizza, 'Prices': pizza_prices } extra = ["Fries", "Salad", "Garlic Bread", "Lemonade", "Fanta", "Cola"] extra_prices = [5, 7, 15, 4, 3, 5] extra_menu = { 'extra': extra, 'Prices':extra_prices } payment = ["cash", "credit"] # Main program make_statement("welcome to chud pizzas", "🍕") print() want_instructions = string_check("would you like to know how to order? ") if want_instructions == "yes": instructions() print() print("program continues...") # Rearranging index- p_menu = pandas.DataFrame(pizza_menu) # Rearranging index p_menu.index = np.arange(1, len(p_menu) + 1) print(p_menu) # Rearranging index- e_menu = pandas.DataFrame(extra_menu) # Rearranging index e_menu.index = np.arange(1, len(e_menu) + 1) print(e_menu) # Ask the user how many pizzas would they like pizzas = int_check("How many pizzas would you like", 1, 10) print(f"You've selected {pizzas} pizzas") while number_of_pizzas < pizzas: items = string_check(f'what would you like?', {items}, 1) # Ask for their age and check it's between 5 and 20 items_2 = int_check("Enter the number of items between 5 and 20 ", 5, 20) print(f"You've selected {items_2} items") pay_method = string_check("Choose a payment method cash(c) or credit(cr): ", payment, 2 ) if pay_method == "cash": print(f"You chose to pay by cash") else: print(f"You chose {pay_method}") print() print("program has ended")