r/learnpython • u/hispters • Feb 16 '13
What's wrong with my if statement?
Hi everybody, I recently learned a bit of Python from code academy, so I decided to try some on my own. Every time I try to use this if statement, it always comes back as the elf response, even if I put in "orc" or "human".
race=raw_input("Whats your race ")
if race is "elf" or "Elf":
print "Hello, noble elf!"
elif race is "orc" or "Orc":
print "You do not belong here... leave this place"
else:
print "I don't recognize you."No matter what I put it, it replies with "Hello, noble elf!".
Any help? Am I even using the same version of CodeAcademy? (Also why do I use "is" not "=" in the if statement now?) Thanks everybody!
P.S.: I've noticed if I say:
num=3
print num*4it prints 4444, not 12. Could somebody help me with my syntax? Thanks so much!
11
Upvotes
9
u/Advent667 Feb 16 '13
ok i am not sure how the "is" operator works but i fear that is your problem.
you ask why you can not use "=" well that is because it is the assignment operator, you need the comparison operator "==" so your if statement should read like
for both elf and orc and then it worked fine for me. I make the assignment/comparison operator mixup all the time :) I hope this helps