SyntaxError: Missing parentheses in call to 'print' in Python

Dung Do Tien Sep 30 2021 127

Hello you guys, I am a newbie in Python and I'm also studying more about Python.
I have some lines of code, I want to learn more about input and output in Python, I used to input() and print methods to help do it. Function as below:

name = input("Enter your name :")
phone = input("Enter your phone :")
age = input("Enter your age :" )
address = input("Where are you from :")
print "Hello, World! My name is " + name
print "I'm " + age + " and come from " + address
print "Pls connect with me by phone number " + phone

But I get an exception SyntaxError: Missing parentheses in call to 'print' when I run code above. I code refer by some example on the internet.

  File "main.py", line 5
    print "Hello, World! My name is " + name
          ^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print("Hello, World! My name is " + name)?

And I am using python 3.8.2

Anyone can explain it to me? How can I solve it?

Thanks for any suggestions.

Have 2 answer(s) found.
  • M

    Manish Kumar Sep 30 2021

    You need to learn Python by version. From Python 3.x you must to use print("") instate of print "". With your example you can do as below:

    name = input("Enter your name :")
    phone = input("Enter your phone :")
    age = input("Enter your age :" )
    address = input("Where are you from :")
    print("Hello, World! My name is " + name)
    print("I'm " + age + " and come from " + address)
    print("Pls connect with me by phone number " + phone)

    #Output

    Enter your name :Python
    Enter your phone :07878677876
    Enter your age :15
    Where are you from :USA
    Hello, World! My name is Python
    I'm 15 and come from USA
    Pls connect with me by phone number 07878677876

    It's not to hard to fix.

  • S

    Sandeep Kumar Sep 30 2021

    You only use print "something" syntax for Python 2.x. From Python 3.x you have to use print("something") syntax.

    I hope it solve issue for you.

Leave An Answer
* NOTE: You need Login before leave an answer

* Type maximum 2000 characters.

* All comments have to wait approved before display.

* Please polite comment and respect questions and answers of others.

Popular Tips

X Close