Here's the code I have question with:
isPet_list_elem = input("Pet?: ").lower()
# check if the input is either y or n
while isPet_list_elem != "y" or isPet_list_elem != "n":
print("Please enter either 'y' or 'n'.")
isPet_list_elem = input("Pet?: ").lower()
I keep thinking that the loop would end when I enter either "y" or "n", but the loop continues to ask me for another input even after entering either y or n.
I've tried using other while loop to do the same, but the result was the same. What should I do to avoid this error?
whileclause should beandand notor.orto return True for either situations?isPet_list_elem = "n"thenisPet_list_elem != "y"is true, so the total expression is true. IfisPet_list_elem = "y"thenisPet_list_elem != "n"is true, so your total expression is true. So in any case your expression is true.