-2

I'm a beginner of Python and I got a problem here. I just copied what my textbook says but I got an error here. I put the following code.

if return_age != 0:
    print"Your age is %s years" %(return_age)

Then my laptop says

File "<ipython-input-3-8c2f6bc68809>", line 15
 print"Your age is %s years" %(return_age)
                              ^
SyntaxError: invalid syntax

Please explain how to correct this bug. Thanks in advance.

Hossein
  • 21,768
  • 32
  • 114
  • 200

4 Answers4

3
# works in python 2
return_age = 4
if return_age != 0:
    print "Your age is %s years" %(return_age)

# works in python 3 
return_age = 4
if return_age != 0:
    print("Your age is %s years" %(return_age))

https://docs.python.org/2/reference/simple_stmts.html#the-print-statement

https://docs.python.org/3/library/functions.html#print

Tanmay jain
  • 794
  • 5
  • 10
1

Print is a function in Python 3, so you need parentheses.

Simon
  • 10,402
  • 1
  • 28
  • 44
1

If you're using python 3.x Try this

print("Your age is %s years" %(return_age))
Vaibhav Sharma
  • 891
  • 4
  • 14
0
 print"Your age is %s years" %(return_age)

You are using Python 3.x version and using a Python 2.x code.

If you want to use Python 2.x then this code will work.

Or else use the following code:

print("Your age is %s years" %(return_age))
Hossein
  • 21,768
  • 32
  • 114
  • 200
excelislife
  • 347
  • 4
  • 17