Click here to Skip to main content
16,009,114 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
num = int(input("enter number: "))

if num == 0                     #(error at this line "invalid syntex")
        print ("number is 0")
    elif mod = num % 2:
        if mod > 0:
            print "it is even number"
            else:
                print "it is odd number"

What I have tried:

tried everything, what I am understand, like 
by putting only one =
placing , : at end of line
put 0 into bracket (0)
etc.
Posted
Updated 24-Dec-19 3:00am
Comments
Maciej Los 24-Dec-19 3:07am    
As to me: it looks correct.
Ksonivid 24-Dec-19 9:01am    
still error appears, how can i show you screen shot ?
I am using anaconda + spyder

Try adding the double dots colon, like
Python
...
if num == 0:
...

Also you need to check the indentations and use parenthesis for the print statements, something like
num = int(input("enter number: "))

if num == 0:
    print ("number is 0")
else:
    mod = num % 2
    if mod > 0:
        print("it is even number")
    else:
        print("it is odd number")
 
Share this answer
 
v5
Comments
Maciej Los 24-Dec-19 3:03am    
Mika, why?
Wendelius 24-Dec-19 3:31am    
You're right, using semicolons is not mandatory. It's just an old, persistent habit :)
Maciej Los 24-Dec-19 4:01am    
I thought that using double dots changes something... I can't see the documentation for using double dots in python.
I'm afraid, your answer won't help OP.
Maciej Los 24-Dec-19 4:10am    
Ohh....
If you wanted to say that double dots means a colon (which i missed in your answer), you're right, Mika.
Wendelius 24-Dec-19 4:19am    
Yep, that would be a colon
Python
if num == 0                     #(error at this line "invalid syntex")

You are missing the colon (:) from the end of the statement. It should be:
Python
if num == 0:
 
Share this answer
 
Comments
Maciej Los 24-Dec-19 4:06am    
Hawk eye!
Richard MacCutchan 24-Dec-19 4:17am    
It's one of those mistakes that is so easy in Python. And having done it myself so many times, I trend to look more carefully these days.

Happy Christmas to you by the way.
Maciej Los 24-Dec-19 8:52am    
Thank you very much, Richard.
Happy Christmas to you too.
As i mentioned in the comment to the question, your code looks good to me... I was wrog! A colon is missed. See soultion #2.

I'd suggest to debug your program. See: Intro Python Debugging[^]
This article Invalid Syntax in Python: Common Reasons for SyntaxError – Real Python[^] might be helpful also.
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900