Python Forum
SyntaxError: Missing parentheses in call to 'print' - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: SyntaxError: Missing parentheses in call to 'print' (/thread-10966.html)



SyntaxError: Missing parentheses in call to 'print' - sofret - Jun-15-2018

Am new to python, a new concept which i love.... i started 3days back.... and am using a text book to teach myself.... i got to a section of the textbook and i saw a new concept which i love.but i entered the code the way it was entered in the text book.... but the program did not run...here is the code, and the result i was getting.......

>>> x = input("x:")
x:50
>>> y = input("y:")
y:50
>>> print x*y
SyntaxError: Missing parentheses in call to 'print'. Did you mean print(x*y)?



RE: i need help - buran - Jun-15-2018

you are using python3 (good), but maybe your book is targeted at python2. If this is the case - change the book you are using.
As to the particular error - in python2 print is a statement, while in python3 it is a function thus it requires parentheses.
On the other hand python3 uses input, while python2 equivalent is raw_input, so I'm not 100% your book is for python2. If it is python2 book and teaches you to use input in python2, it's a poor textbook, definitely don't use it.


RE: i need help - volcano63 - Jun-15-2018

(Jun-15-2018, 01:13 PM)buran Wrote: On the other hand python3 uses input, while python2 equivalent is raw_input, so I'm not 100% your book is for python2. If it is python2 book and teaches you to use input in python2, it's a poor textbook, definitely don't use it.

In Python2, input exists too - but it evaluates the entered expression, that's what would have allowed OP to multiply without conversion.

Python2 input would return number - if number is entered - due to expression evaluation. Unfortunately, it would allow to execute a valid Python command, if entered - the reason why it (input) is considered dangerous, and its usage discouraged.

raw_input in Python2 returns string

So the book is definitely Python2 - and also correct, though uses discouraged practice.


RE: i need help - buran - Jun-15-2018

I also realised that multiplies without conversion to int/float. Just didn't want to complicate things with input()/eval(input()) explanations. I didn't claim it's incorrect, just poor textbook for newbie