2

So my code says this:

a = input("Choose a letter")

if a == "A" or "B" or "D":
cr = "false" 

elif a == "C":
  cr = "true"

if cr == "false":
 print("Sorry you did not asnwer correctly")
 import sys
 sys.exit()

elif cr == "true":
 print("Well done!")

But for some reason, whatever I put, it says it is wrong. Any help? I am new to python and have come from Lua.

2 Answers2

3

if a == "A" or "B" or "D": this evaluates to TRUE always. Because "B" or "D" always evaluates to TRUE everytime. So this might boil down to if 0 or 1 or 1 no matter what.

To fix this you need compare after every conditional operator. if a == "A" or a == "B" or a == "D":

timgeb
  • 76,762
  • 20
  • 123
  • 145
Vineeth Sai
  • 3,389
  • 7
  • 23
  • 34
2
if a == "A" or "B" or "D":
   cr = "false" 

Is wrong. You want:

if a == "A" or a == "B" or a == "D":
   cr = "false" 

One nice thing you could do is this:

if a in [ 'A', 'B', 'D' ]:
   cr = "false"

Or even better rewrite your script to this:

a = input("Choose a letter")

if a == 'C':
 print("Well done!")
else:
 print("Sorry you did not asnwer correctly")
 import sys
 sys.exit()
Red Cricket
  • 9,762
  • 21
  • 81
  • 166