Search code examples
pythonpython-3.3python-idle

Python 3.3.2 syntax error using ":" in If-else


>>> x = 15
if (x/2)*2 == x:
    print ('Even')
    else:
    print ('Odd')

SyntaxError: multiple statements found while compiling a single statement
>>> x = 15 if (x/2)*2 == x:
    print ('Even')
    else:
    print ('Odd')

SyntaxError: invalid syntax 

Solution

  • you can't write several statement in one line in python, write

    x = 15 
    if (x/2)*2 == x: 
       print ('Even') 
    else: 
        print ('Odd')
    

    here:

    enter image description here

    and got

    enter image description here