0

I've just begun learning Python and I'm using the IDLE ide to learn programming. I've been trying a basic code I saw on the official site but it keeps saying 'Incorrect Syntax' and highlights the keyword 'else' here's the program:

a=40
if a <= 40:
    print("True")
    else:

The 'else' is highlighted and I'm told it's a syntax error. Can anyone tell me what I'm doing wrong?

3
  • 5
    In Python, Whitespace is part of the syntax. The syntax error lies in your usage of whitespace. Commented Feb 25, 2013 at 11:16
  • 3
    Pro tip: When learning a new language or library, or anything, if you get a syntax error you can assume you did something wrong. 99.99% of the time it is not a bug. Commented Feb 25, 2013 at 11:21
  • @Volatility: Which only illustrates all the more why the OP doesn't understand what is wrong. I indented it to match the original error image. Commented Feb 25, 2013 at 11:22

2 Answers 2

3

The else block needs to be indented at the same level as the if block.

if a <= 40:
    print('True')
else:
    print('False')
Sign up to request clarification or add additional context in comments.

Comments

0

You need to fix your identation for the else: clause (even when working on the console). The alignment of else: has to agree with that of the if

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.