Skip to content
← Back to Community
My If Statements don't work...
Profile icon
PythoNinja

Hello! I am making a game, and I wrote two if statements, and when I hit the run button and type in an answer, it goes to only one if statement when it is supposed to go to the other. I don't know what's happening!

Answered by mkhoi [earned 5 cycles]
View Answer
Voters
Profile icon
oskar120100
Profile icon
PythoNinja
Comments
hotnewtop
Profile icon
gibbsfreenergy

Is this the repl? https://repl.it/@PythoNinja/WealthyMountainousConversions#main.py
As far as I can see this is the best Python 3 game I've ever seen! If this helped then please choose this as the correct answer to your question! Happy coding and a great day

Profile icon
PythoNinja

@JosephSanthosh Thank you, but I must admit, it is not my game. I used it to make a map for a different game, and it is the exact same thing as @Mkhoi's STACKMAN game. The game I am doing is a team game, Dungeon of the Dark Lord. This is the link: https://repl.it/@Ninjas/Dungeon-of-the-Dark-Lord#main.py . In main.py, on line 13 is a def cocker. Under that is two if statements and a login system. The If Statements are the problems.

Profile icon
mkhoi

@PythoNinja oh, you have to write it like this:

if sl == "Load" or sl == "load" or sl == "1":

And same thing for the other if statement
Your problems are because of if you use the 'and', 'or',... keyword then the condition after that is separated from the condition before. So it checks if 'load' or '1' is true, and they are, then runs the code below and skip the next if statement. I hope this is a good explaination :)

Profile icon
PythoNinja

@mkhoi Every time I try to press "1" or "2" then enter, it will just load the menu again.

Profile icon
mkhoi

@PythoNinja hmm, i don't really know how to fix this.

BTW, i see you're trying to make the user input be capitalized, you have to add a pair of brackets after the 'upper' keyword there, like this: sl = input().upper(). And in the cocker function, change the conditions like this:

if sl == "LOAD" or sl == "2":

That's because the input will be capitalized but the conditions only check for input that isn't capitalized, so your code wouldn't run. And i don't know why the numbers don't work, i think they are unaffected by the capitalization but for some reason they don't work?

Profile icon
PythoNinja

@mkhoi Wow, thanks! But every time I finish the registration, it turns back to the menu.

Profile icon
mkhoi

@PythoNinja looking at the code, i don't think that should have happened. Maybe it could be a problem with replit itself but i'm not really sure.

Profile icon
PythoNinja

@mkhoi Ok thanks for your help!

Profile icon
PattanAhmed

@PythoNinja Hi,
It's kind of weird and fun game but I can't find any kind of errors in your game
If you really find one, then please comment me below!
Thanks and waiting for your reply.

Hope this helps
Please mark my answer if this helps.

Profile icon
[deleted]

Link repl! Heres a simple image on how to do it:

Screenshot 2020-08-05 at 9

Profile icon
PythoNinja

@CarlosRosiles I'm sorry, I couldn't do it since it was a Team repl.

Profile icon
[deleted]
Profile icon
Bookie0

Hello there I will we glad to be if assistance just link the repl please ;)

Profile icon
Coder100

Hi! Send repl.