# Functions go here def make_statement(statement, decoration): """Emphasises headings by adding decoration at the start and end""" return f"{decoration * 3} {statement} {decoration * 3}" def string_check(question, valid_ans_list=('yes', 'no'), num_letters=1): """Checks that users enter the full word or the first letter of a word from a list of valid responses""" while True: response = input(question).lower() for ITEM in valid_ans_list: # check if the response is the entire word if response == ITEM: return ITEM # check if it's the first letter elif response == ITEM[:num_letters]: return ITEM print(f"Please choose an option from {valid_ans_list}") def instructions(): make_statement("Instructions", "ℹ️") print(''' Welcome to 🍭 Candy land 🍭 — your virtual sweet shop! Here’s how this tasty adventure works: 1. You’ll start by entering your name and setting a budget (how much you’re allowed to spend). 2. You’ll be shown a list of delicious sweets with their prices. 3. You can keep buying sweets (by choosing their number) as long as you stay within your budget. 4. If you try to buy something more expensive than what you can afford, you’ll get a friendly reminder. 5. Once you can no longer afford any more sweets, the program will end and say goodbye! Let’s get snacking! 🍬🍫🍭 ''') 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.") def int_check(question, low, high): """Checks users enter a budget between two values""" error = f"Oops - please enter an integer between {low} and {high}." while True: try: response = int(input(question)) if low <= response <= high: return response else: print(error) except ValueError: print(error) # Main Routine goes here # Program main heading print(make_statement("Candy land", "🍭")) # Ask user for their name (and check it's not blank) print() name = not_blank("Name: ") # Ask user if they want to see the instructions print() want_instructions = string_check(f" Hi {name}, Do you want to see the instructions? ") if want_instructions == "yes": instructions() print() # ask for budget budget = int_check("What is your budget? (Maximum Budget of $20) ", 1, 20) print(f"Your budget is ${budget}") print()