-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
  • 24,202
  • 35
  • 119
  • 224
Makoto Nakai
  • 61
  • 2
  • 8

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
  • 814
  • 6
  • 11
1

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

Simon
  • 10,679
  • 1
  • 30
  • 44
1

If you're using python 3.x Try this

print("Your age is %s years" %(return_age))
static const
  • 953
  • 4
  • 16
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
  • 24,202
  • 35
  • 119
  • 224
excelislife
  • 357
  • 5
  • 18