FallenRune
FallenRune

Reputation: 9

Syntax error in simple Python program with if statement

I have this code:

num = int(input("Enter a number: ")
if num%2 == 0:
    print("The number is even")

else:
    print("The number is odd")

Why do I get a syntax error on the if statement line?

Upvotes: 0

Views: 77

Answers (2)

retep
retep

Reputation: 227

As stated by @mikeb, the error in on the previous line, where
num = int(input("Enter a number: ") should be
num = int(input("Enter a number: ")).
When you are looking for an error, always check the previous line as well.

Upvotes: -2

mikeb
mikeb

Reputation: 11267

num = int(input("Enter a number: "))
if num%2 == 0:
    print("The number is even")

else:
    print("The number is odd")enter code here

Missing a ) on the line before. Lots of times when you get syntax errors on a line it happens at that line or a line or a few lines before that, in your case it's looking for a matching paren.

Upvotes: 0

Related Questions