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 # Return actual item (with correct casing) elif response == item_low[:num_letters]: return item print(f"Please choose an option from {valid_list}") # Main routine goes here # Initialise pizza numbers MAX_PIZZAS = 5 pizzas_sold = 0 while True: 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"] # Ask for pizza type choose_pizza = input("Choose a gourmet option (or 'xxx' to quit): ").lower() if choose_pizza == "xxx": print("Exiting pizza ordering...") break chosen_size = string_check("What size of the pizza would you like? ", pizza_sizes, 2) print(f"You chose {chosen_size}") extra_toppings_pizza = string_check("Would you like extra toppings? ", yes_no_list, 3) print(f"You chose {extra_toppings_pizza}") if extra_toppings_pizza == "yes": extra_toppings_choose = string_check("Extra toppings: ", extra_toppings, 99) print(f"you chose {extra_toppings_choose}") want_special_pizzas = string_check("We have limited edition special pizzas, are you interested? ", yes_no_list, 4) print(f"you chose {want_special_pizzas}") if want_special_pizzas == "yes": special_pizzas_choose = string_check("What type of special pizza would you like? ", special_pizzas, 99) print(f"you chose {special_pizzas_choose}") # Every time a pizza is ordered, it adds 1 out of the 5 threshold pizzas_sold += 1 # Once pizza has reached 5/5, the program breaks continuing to something else if pizzas_sold >= MAX_PIZZAS: print(f"You've reached the maximum of {MAX_PIZZAS} pizzas.") break another_pizza = string_check("Would you like another pizza? 🍕 ", yes_no_list, 4) print(f"You chose {another_pizza}") if another_pizza == "no": break