def get_yes_no_input(prompt_message): """ Prompts the user for a yes/no input and returns True for yes, False for no. Handles variations like 'y', 'yes', 'n', 'no' (case-insensitive). """ while True: user_input = input(f"{prompt_message} (yes/no): ").lower().strip() # conver to lower case and remove trailing white spaces. if user_input in ('yes', 'y'): return True elif user_input in ('no', 'n'): return False else: print("Invalid input. Please enter 'yes' or 'no'.") # Example usage: if get_yes_no_input("Do you want to continue?"): print("Good. Here is another question.") else: print("User chose to stop.") answer = get_yes_no_input("Is life a box of chocolate?") if answer: print("Great!") else: print("Then, get pizza.")