Reputation: 402
I'm sure this is super basic to everyone but for some reason I cannot figure out the code below only prints out "Glad to see you back at it again."
I'm new to programming and this is my first attempt to create something small to interact with. Any ideas why the other options in elif and else dont print?
def was_read():
print "Have you read this before?"
read = raw_input('Yes or No? ')
if read == 'Yes' or 'yes':
print 'Glad to see you back at it again.'
elif read == 'No' or 'no':
print 'Hope its a good one then!'
else:
print "I'm sorry I didn't understand that"
was_read()
Upvotes: 0
Views: 112
Reputation: 298432
While Python may look like English, it isn't English. What you wrote will it be interpreted like:
if (read == 'Yes') or ('yes')
'yes'
is truthy, so your if
statement really acts like:
if (read == 'Yes') or True
False or True
and True or True
are both True
, so your first if
statement will always be true.
Be explicit:
if read == 'Yes' or read == 'yes'
Or just do it the simpler way:
if read.lower() == 'yes'
Upvotes: 5