1

So I have the code set up where if the input is not yes or no print("Type Yes or No") but even if I type yes or no the message is still printed.

mylist = []
are_you_done = "no"
while are_you_done != "yes":
    grocery_item = input("Add to Grocery ")
    are_you_done = input("Are you done? ").lower()
    mylist.append(grocery_item)
    if are_you_done != "yes" or are_you_done != "no":
        print("Type Yes or No")
        are_you_done = input("Are you done? ").lower()



for item in mylist:
    print(item)
4
  • 2
    if are_you_done != "yes" or are_you_done != "no"— This condition is always true. A string cannot be equal to both "yes" and "no", so it is always unequal to at least one of them. Commented Dec 24, 2019 at 20:38
  • 1
    @khelwood. Sorry, I'm illiterate. I just realized that you're suggesting swapping or to and, and that's correct of course Commented Dec 24, 2019 at 20:42
  • @khelwood You're right. The condition should have "and" instead of "or" Commented Dec 24, 2019 at 20:44
  • @MadPhysicis Cool =). I reread it about four times to make sure I hadn't mixed it up. Commented Dec 24, 2019 at 20:46

2 Answers 2

1
if are_you_done != "yes" or are_you_done != "no":

This condition is always true. A string cannot be equal to both "yes" and "no", so it is always unequal to at least one of them.

You mean

if are_you_done != "yes" and are_you_done != "no":

or

if are_you_done not in {"yes", "no"}:
Sign up to request clarification or add additional context in comments.

Comments

0

You have two conditions in your if statement and if either one is true, then the question will be printed. In other words, for the question to not be printed, then both must be true. In other words, for the question to be skipped, the value in are_you_done must be both yes and no at the same time.

Comments