Python 2.7.8 print statement “Syntax Error: invalid syntax” in terminal(14.04) but running well on vim, why?
Following program prints the sum of squares, First I try to run this problem on terminal it is giving the "Syntax Error: invalid syntax" but when copied the same code on vim editor and run on terminal python for.py (Name of the file is for.py), It is giving no error, please explain the reason behind it.
On Running direct on terminal
Type "help", "copyright", "credits" or "license" for more information.
>>> squares= [1, 4, 9, 16]
>>> sum=0
>>> for num in squares:
... sum+=num
... print sum
File "<stdin>", line 3
print sum
^
SyntaxError: invalid syntax
On vim
$ vim for.py
squares= [1, 4, 9, 16]
sum=0
for num in squares:
sum+=num
print sum
python for.py
output:30 #Running correctly
After suggesting by @mgilson and @ohope5, it working thanks
Type "help", "copyright", "credits" or "license" for more information.
>>> squares=[1, 4, 9, 16]
>>> sum=0
>>> for num in squares:
... sum+=num
...
>>> print sum
30