def string_check(question, valid_ans_list, num_letters): """Check that users enter a 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_ans_list: if response == item: return item elif response == item[:num_letters]: return item print(f"Please choose an option from the list {valid_ans_list}") while True: bye = ["continue", "exit"] leave = string_check("Exit or continue? ", bye, 1) # Exit loop if leave == "continue": continue elif leave == "exit": break