What is wrong here? Upon entering 3 (<=5), the output should be, I think, "Phew, ..." but it stays as "Awesome, ..."
weather = raw_input('How is the weather today, from 0 to 10? ')
answer = raw_input ('Are you in mood to go out? ')
if weather >= 5:
if answer == 'Yes':
print 'Awesome, I will go out!'
print 'Will you come with me?'
else:
print 'Awesome, I am going out now!'
elif weather <= 5:
print "Phew, I didn't want to go outside, great, I will stay in! Thank God!"
else:
print "Huh?"
raw_input returns a string not an integer, e.g. '3' instead of 3.
In Python 2, strings always compare greater than integers so weather >= 5 is always true.
To fix this, cast weather to an integer:
weather = int(raw_input('How is the weather today, from 0 to 10? '))
raw_input returns a string and you need to convert it to integer.
weather = int(raw_input('How is the weather today, from 0 to 10? '))
And you need to catch any exceptions for handling wrong inputs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With