1

So, I Am trying to create some code, and for whatever reason the following always gives the same output, "Great! let's continue"

I am fairly new programmer, so any explanation has about why this is happening and how I can fix it is welcome. Thank you!

#python 2
UserAnswer = raw_input('Is your age and birthday correct? (yes/no):')
if UserAnswer == 'yes' or "Yes":
   print ("Great! let's continue.")
elif UserAnswer == 'no' or "No":
  print("check for your error, the program will now end")
  SystemExit
else:
   print 'Invalid input.'
TheRIProgrammer
  • 87
  • 1
  • 3
  • 10

2 Answers2

1

Don't do:

if UserAnswer == 'yes' or "Yes":

Do instead:

if UserAnswer == 'yes' or UserAnswer == "Yes":

Same applies to the elif condition

Nir Alfasi
  • 53,191
  • 11
  • 86
  • 129
1

The following line will always evaluate to True:

if UserAnswer == 'yes' or "Yes"

This is because "Yes", when treated as a boolean, evaluates to True. So the result of the OR will be True. You can fix it by changing it to the following (and do the same thing for the other line)

if UserAnswer == 'yes' or UserAnswer == 'Yes'
Matt O
  • 1,336
  • 2
  • 10
  • 19