Skip to content
← Back to Community
Having trouble with an "elif" statement
Profile icon
GarretOgden

This file cannot be displayed:

Answered by PYer [earned 5 cycles]
View Answer
Voters
Profile icon
HendelBeauge
Profile icon
YaqubAhmed1
Profile icon
ZahidHossain1
Profile icon
GarlicGnarly
Profile icon
brangme123
Profile icon
GarretOgden
Profile icon
PYer
Comments
hotnewtop
Profile icon
GarretOgden

@PYer If it's not too much trouble, would you be able to help?

Profile icon
PYer

@GarretOgden of course is there a repl link?

Profile icon
GarretOgden
Profile icon
PYer

@GarretOgden Got it! you cant unindent code between elif statements. You did:

elif (choice4 == 1): print ("Mario is struck down by the fire ball, and princess peach returns to Bowser. GAME OVER!") winlose = False health = 0 lives = 0 enemys = 0 elif choice2 == 2: print ("You and Mario are struck by the deadly speeding Bullet, GAME OVER!") winlose = False

You have to indent it since it is part of the statement. Otherwise it will cause an error.

if (choice4 == 2): print ("You and Mario have Saved the princess and saved the day, CONGRATULATIONS!!") winlose = True elif (choice4 == 1): print ("Mario is struck down by the fire ball, and princess peach returns to Bowser. GAME OVER!") winlose = False health = 0 lives = 0 enemys = 0 elif choice2 == 2: print ("You and Mario are struck by the deadly speeding Bullet, GAME OVER!") winlose = False health = 0 lives = 0 enemys = 2 #Create the first choice/the second path (right) for the user elif choice1 ==2: print ("You chose right, the army of Goombas is heading your way, what do you want to do?")

On lines 41 - 58, needs to be changed to:

if (choice4 == 2): print ("You and Mario have Saved the princess and saved the day, CONGRATULATIONS!!") winlose = True elif (choice4 == 1): print ("Mario is struck down by the fire ball, and princess peach returns to Bowser. GAME OVER!") winlose = False health = 0 lives = 0 enemys = 0 elif choice2 == 2: print ("You and Mario are struck by the deadly speeding Bullet, GAME OVER!") winlose = False health = 0 lives = 0 enemys = 2 elif choice1 ==2: print ("You chose right, the army of Goombas is heading your way, what do you want to do?")

Make sure to indent all other places i may have missed.
Please mark this as the correct answer Sorry i was late, i was working on a game

Profile icon
PYer

@GarretOgden read my response

Profile icon
GarretOgden

@PYer Yes, thank you. Unfortunately it is still coming up as an error.

Profile icon
Pythonier
Profile icon
PYer

@GarretOgden can you fix it and then i can look?

Profile icon
PYer

@GarretOgden line 43 is indented an extra time. can you mark my answer as correct since it solves the problem?

Profile icon
GarretOgden

@PYer Sure, sorry about that

Profile icon
PYer

@GarretOgden yeah. its fine.

Profile icon
GarretOgden

https://repl.it/@GarretOgden/Super-Mario-Final-Draft
So, now I'm having trouble with it recognizing my name when I put it in.

Profile icon
Pythonier

I think I may have fixed it: https://repl.it/@Pythonier/WanHighPoints
Your main problems were the indenting and including an extra spaces between stuff like print() and input() ex:

# should be written like a = input("?") print(a) # not this: a = input ("?") print (a)

Hope this helps

You can copy and paste the code or fork it by changing anything in the code

Profile icon
PYer

@Pythonier False. Python ignores whitespace like that. You can see my commented answer below

Profile icon
Pythonier

@PYer My bad! :(

Profile icon
PYer

@Pythonier its fine

Profile icon
GarretOgden

@PYer So, I copied the correct code that you gave me. It is still not running.

Profile icon
GarretOgden
Profile icon
PYer

@GarretOgden is it working

Profile icon
GarretOgden

@PYer It is now showing something with line 44

Profile icon
PYer

@GarretOgden line 43 is not indented

Profile icon
GarretOgden

@PYer Just indented it, now it says that it should not be indented

Profile icon
PYer

@GarretOgden hold on

Profile icon
PYer

@GarretOgden k hold on

Profile icon
PYer

@GarretOgden ALL ERRROS FIXED: You also need to use python 3 not python 2: https://repl.it/@PYer/InexperiencedLuxuriousTechnology

Profile icon
GarretOgden

@PYer Almost there! For some reason, when you choose option two in the beginning it skips all of the other choices and goes straight to the Bowser choice from the first choice/path.

Profile icon
GarretOgden

@PYer The program is supposed to ask the user which path they want. if they choose path 1 then they run into the Bullet Bill and then the Hammer Bro. and Finally to Bowser. The first path is listed as just choice1, choice2, exct. However, when the user chooses path two, they run into the army of Goombas, a Chain chomp, and then Bowser. Those choices are the alt choices.

Profile icon
PYer

@GarretOgden what part do you want it to go too? sorry i am late for responding

Profile icon
GarretOgden

@PYer Ok, the program starts with asking the user for their name, they input it. Then it'll ask them which path they want to take, telling them what is on the left and what is on the right. If they input 2 for their choice (right) it is supposed to go to the elif choice1 ==2: print "You chose right, the army of Goombas is heading your way. What do you do?" and then it will take the user through the altchoice statements. Those being the Army of Goombas, the Chain Chomp, and finally to the fourth alternate choice with Bowser. Hope that kind of clarified it a little.

Profile icon
GarretOgden

@PYer So, if the user chooses to go right (2), then the program should skip over the first set of choices and go to the elif choice1 == 2 statement.

Profile icon
PYer

@GarretOgden do you want a live multiplayer session? https://repl.it/live/ssFgzMNrzJSDbg

Profile icon
GarretOgden

@PYer I'm sorry, but what's that?

Profile icon
PYer

@GarretOgden we can work together on the same repl

Profile icon
GarretOgden

@PYer Oh ok, sure! How would I start that?

Profile icon
PYer

@GarretOgden go to the side of your repl and the file names. then click multiplayer, and click start session. then send me a link

Profile icon
PYer
Profile icon
GarretOgden

@PYer It's getting there! For some reason it is still skipping some steps/print statements. More specifically with the Chain Chomp.

Profile icon
GarretOgden

@PYer Also, here is the multiplayer link https://repl.it/live/0aAPnC3lYtss1w

Profile icon
PYer

@GarretOgden i got to leave i'll be back in about 3 hours

Profile icon
GarretOgden

@PYer Ok, see ya then

Profile icon
PYer

@GarretOgden k i am here

Profile icon
GarretOgden

@PYer Hey, I'm so sorry to be getting back to you so late. I unfortunately had to run a few errands. But unfortunately due to a family thing that came up, I probably won't be able to work on it again until later tonight. The only thing that I need help fixing now are the alternate choices 3 & 4. The one with the Chain Chomp and Bowser.

Profile icon
GarretOgden

@PYer Fixed the Chain Chomp section, now all that's left is the Army of Goombas!

Profile icon
GarretOgden

@PYer Was able to fix the whole program! Thank you so much for your help, I really do appreciate it! :)

Profile icon
PYer

@GarretOgden sorry i cant work until monday

Profile icon
PYer

@GarretOgden no problem

Profile icon
Steven_The_GuyT

Here is a sample for python:

x = 0 if x == 1: print('x=1') elif x == 0: print('x=0') else: print('x doesn't equal 0 or 1')

This would print out:
x=1

Profile icon
GarretOgden

I am currently working on a school project with Python and am having trouble with a certain elif statement on line 50 of my program. I've tried everything, from spacing to even just changing it to an if statement. Please help!

Profile icon
Vandesm14

@GarretOgden Do you mind placing the code in a repl? Then the indentation won't be an issue

Profile icon
GarretOgden

@Vandesm14 How would I do that to where you can see it? Sorry I'm still kind of new with repl.

Profile icon
Vandesm14

@GarretOgden If you go to: https://repl.it/repls and click the "New Repl" at the top, select Python[2 or 3] from the language box and hit create, send me the url of that repl once it loads.

This file cannot be displayed: https://storage.googleapis.com/replit/images/1556835719375_f85a99d5b7690ae0897a2c9cf49170da.pn

This file cannot be displayed: https://storage.googleapis.com/replit/images/1556835754177_f91dd41ebe08b2dd275df9da90562aec.pn

Profile icon
GarretOgden
Profile icon
Vandesm14

@GarretOgden You don't need parentheses in the statement: elif a == b:

Profile icon
GarretOgden

@Vandesm14 Is that what the problem was?

Profile icon
Vandesm14

@GarretOgden If you remove the parentheses from the elif statements, it should fix your problem.

Please mark this as answered if I helped your problem 👍

Profile icon
GarretOgden

@Vandesm14 Just removed the parentheses from all the elif statements, it's still popping up with line 50 in specific. Should I do it with all the if statements as well?

Profile icon
Vandesm14

@GarretOgden @PYer I cannot help him past this point as I am not good at python

Profile icon
GarretOgden

@Vandesm14 Oh ok, well thank you so much for your help. I really appreciate it!

Profile icon
PYer

@Vandesm14 is there still more help needed?

Profile icon
GarretOgden

@PYer Yes please, I still can't seem to fix the issue with that elif statement. Any chance it's something else?

Profile icon
Vandesm14

Can you post the link to the repl?

Profile icon
GarretOgden

@Vandesm14 I've tried but since the project is a notepad file I don't think it will take it.

Profile icon
ReplTalk

Hey there, please make sure your post body is at least 10 words and 100 characters. That makes it easier for our community to help you!