DIGIT-ARC read-only archive · snapshot: July 23, 2026

Problem with Python Shell

10 posts · originally from https://geek.digit.in/community/threads/problem-with-python-shell.140726/

A
ankurankan Original post #1
May 13, 2011 at 7:07 PM
Whenever i use the print statement it returns a syntax error.What should I do?


Python 3.2 (r32:88445, Feb 20 2011, 21:30:00) [MSC v.1500 64 bit (AMD64)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> print 52*4
SyntaxError: invalid syntax
>>> print 52
SyntaxError: invalid syntax
>>> a=32
>>> print a
SyntaxError: invalid syntax
>>> print '12'
SyntaxError: invalid syntax
>>> if (a<b):
print 'b is greater'

SyntaxError: invalid syntax
krishnandu.sarkar
May 13, 2011 at 8:27 PM
print() is a function.

So...
print(52*4)

print(52)

a=32
print(a)

print('12')

if(a<b):
print("B is greater")

BTW you can use python as calculator without print too..
*img218.imageshack.us/img218/9808/pythonm.jpg

Uploaded with ImageShack.us


Anyway...Read Docs carefully again..!! *docs.python.org/py3k/tutorial/introduction.html
A
May 13, 2011 at 9:48 PM
thanks....
U
May 14, 2011 at 12:59 PM
you are using python 3.x shell but your syntax is of 2.x series
A
May 17, 2011 at 10:12 PM
Now I am having problem with the else statement


>>> x=21
>>> if x%2==0:
print (x ,"is even")
else:

SyntaxError: invalid syntax
>>>
krishnandu.sarkar
May 17, 2011 at 10:19 PM
Code:
x = 21
if(x%2 == 0):
      print("Even")
else:
      print("Odd")

Again, I highly suggest you to read the docs. Or find some ebook or get a book.

*img841.imageshack.us/img841/4760/pythonz.jpg

Uploaded with ImageShack.us
Liverpool_fan
May 17, 2011 at 10:56 PM
Now I am having problem with the else statement


>>> x=21
>>> if x%2==0:
print (x ,"is even")
else:

SyntaxError: invalid syntax
>>>

Indention mate, make sure the print statement is indented by spaces as compared to your if and else is indented to match the indention of the if statement.
krishnandu.sarkar
May 17, 2011 at 11:31 PM
^^Yup, and his if syntax is also wrong.
A
May 18, 2011 at 3:26 PM
run IDLE, python shell in it will automatically indent the statements.