Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
if statement not working
#4
Quote:Without really getting into the code (there are a number of errors), I would say you need to indent your first if/else statement. In comparisons, you need to use '==' not '='. Change your first 'else' to an 'elif == i' and so on.
To get you started, basically you want
print("Math God")
print("Welcome to Math God! Made by Trent in 2018!")
print("In this game, you have a minute to answer the math problem correctly. If you get it wrong or run out of time, you get a strike. Three strikes and the game is over.")
while True:
    x = input("There are three modes to this game: quadratic, interest, and order of operations. Type 'q' for quadratics, 'i' for interest, and 'o' for order of ops.")
    try:
        if x == 'q':
           print("You have selected quadratics. Press any key to start.")
        elif x == 'i':
           print("You have selected interest. Press any key to start.")
        elif x == 'o':
           print("You have selected order of operations. Press any key to start.")
    except:
        print("Sorry, but you didn't correctly choose a valid mode. Press any key to continue.")
        # return
I got a bad input error on line 8

Quote:Fix the indentation to equal spaces. The if block inside the try/except must be indented.
You can't use just input() in a script without an assignment.
I was just trying for the other inputs to make a "Press any key to continue." kind of thing.
Reply


Messages In This Thread
if statement not working - by trent101010 - Mar-08-2018, 07:14 PM
RE: if statement not working - by wavic - Mar-08-2018, 07:48 PM
RE: if statement not working - by sparkz_alot - Mar-08-2018, 08:19 PM
RE: if statement not working - by trent101010 - Mar-08-2018, 10:52 PM
RE: if statement not working - by trent101010 - Mar-11-2018, 05:02 PM
RE: if statement not working - by wavic - Mar-11-2018, 07:07 PM
RE: if statement not working - by trent101010 - Mar-12-2018, 06:17 PM
RE: if statement not working - by Larz60+ - Mar-11-2018, 08:53 PM
RE: if statement not working - by wavic - Mar-14-2018, 03:19 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Question If, elif, and else statement not working PickleScripts 3 943 Mar-30-2023, 02:53 PM
Last Post: PickleScripts
  If statement not working correctly? MrKnd94 2 857 Nov-16-2022, 02:49 AM
Last Post: deanhystad
  If Statement not working...Why? Milfredo 2 2,231 Oct-17-2020, 03:23 AM
Last Post: Milfredo
  Invoking function in if else statement, not working! ibaad1406 13 5,716 May-30-2019, 09:05 PM
Last Post: ibaad1406
  If statement not working oldcity 4 3,140 Oct-14-2018, 10:45 AM
Last Post: oldcity
  why is this try.....except statement not working? HenryJ 3 8,804 Feb-06-2018, 06:15 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020