samedi 4 mai 2019

I don't understand why my if/elif/else statement isn't working as intended? Fairly easy question to answer I think

enter image description here

I'm practicing using if/elif/else statements, and this program here is supposed to print "Hello" if spam equals 1, "Howdy" if spam equals 2, and "Greetings" if it equals anything else. But for some reason it prints "Greetings" even when spam is equal to 1 or 2.

I even copy and pasted the correct code (from Automate the Boring Stuff with Python Programming) to this practice problem and it still didn't work correctly. Tested it on both PyCharm and the regular IDLE.

print('Please enter a number.')
spam = input()

if spam == 1:
    print('Hello')
elif spam == 2:
    print('Howdy')
else:
    print('Greetings')

Aucun commentaire:

Enregistrer un commentaire