# Functions go here def not_blank(question): """Checks that a user response is not blank""" while True: response = input(question).strip() if response != "": return response print("Sorry, this can't be blank. Please try again.\n") def phone_number_check(question): """Checks users enter an integer that is at least 7 digits long""" error = "Please enter a phone number at least 7 digits long (no spaces, decimals, letters, or symbols)." while True: response = input(question).strip() # Checks if the input is at least 7 digits long if response.isdigit() and len(response) >= 7: return response else: print(error) 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: # 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_answers}") # Loop for testing purposes while True: print() # Ask user for their name (and check it's not blank) name = not_blank("Enter your name: ") # Ask user for pickup or delivery order_method = string_check("Pickup or delivery? (Note: Delivery is $11.99 extra) ", ['pickup', 'delivery']) # If delivery is chosen ask for phone number and address if order_method == "delivery": phone_number = phone_number_check("Phone number: ") address = not_blank("Delivery address: ") else: phone_number = None address = None