def ask_route(animals): # note that now we pass the animal list as a parameter sep = ", " # for displaying list of animals animal_string = sep.join(animals) valid = False # set to false to execute while loop once route = [] while not valid: valid = True print("please list animals you want to see in order, separated by a comma") print("animals are : ", animal_string) answer = input("your answer : ") answer = answer.replace(" ", "") route = answer.split(",") for animal in route: valid = valid and (animal in animals) # at this point, we know route is valid return route # return route