I\'m a newbie to Python and currently learning Control Flow commands like if
, else
, etc.
The if
statement is working all fine
indentation is important in Python. Your if else statement should be within triple arrow (>>>), In Mac python IDLE version 3.7.4 elif statement doesn't comes with correct indentation when you go on next line you have to shift left to avoid syntax error.
It looks like you are entering a blank line after the body of the if
statement. This is a cue to the interactive compiler that you are done with the block entirely, so it is not expecting any elif
/else
blocks. Try entering the code exactly like this, and only hit enter once after each line:
if guess == number:
print('Congratulations! You guessed it.')
elif guess < number:
pass # Your code here
else:
pass # Your code here
if guess == number:
print ("Good")
elif guess == 2:
print ("Bad")
else:
print ("Also bad")
Make sure you have your identation right. The syntax is ok.