-2

I want to run this code in the python 3 but i can't.Whenever i try to run the code,i get the invalid syntax error.

age = 20
name = 'Swaroop'
print '{} was {} years old when he wrote this book'.format(name, age)
print 'Why is {} playing with that python?'.format(name)

Please help me.

Thank you.

user3722727
  • 133
  • 1
  • 1
  • 7

1 Answers1

1

Put parentheses around the print function calls.

print('{} was {} years old when he wrote this book'.format(name, age))
print('Why is {} playing with that python?'.format(name))

In Python2, print is a statement, and does not require parenthesis.

In Python3, print is a function, so it requires parentheses around its arguments.

unutbu
  • 842,883
  • 184
  • 1,785
  • 1,677