Elif Statement Struggles In Python

So I’m having problems with python if elif else statements, It looks like its correct but the only thing that runs is the if statement

**Repl link: I don’t want to provide one^^" **

if you look at the last one the inserted “Race” is, ‘beetle’ which isn’t a listed race so it should print the else statement but it only does what the first statement said, Can someone help me fix this stuff? Im going insane trying to bug fix this…

You need the conditional operator again after your or operator:
if charRace == "Human" or charRace == "human"

Same goes for all your elif statements.

4 Likes

O my god! Thank you! I’m still kinda relearning python after I forgot all of it this helps a bunch!

2 Likes

In addition, if you want to test if one thing equals to anything in a certain amount of item, you can avoid having long statements like if var == "a" or var == "b" or var == "c" or ......(continues and go very very long), you can actually go for an alternate using the in keyword, such like if var in ["a", "b", "c", "extend this like a list"]:, or in this case if charRace in ["Human", "human"]
Please note this only works for equality (==) and inequality(!=, by adding the not keyword in the front) but not other type of comparison, you need to refer to @MrBrash’s solution for those.

5 Likes

Just to mention - because I like warning new programmers - these sorts of alternative methods are language specific. You wouldn’t be able to do that in many other languages. But they can be really helpful and are definitely one of the reasons people love Python so much.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.