Problem with Python Shell

ankurankan

Right off the assembly line
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

Simply a DIGITian
Staff member
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
 
OP
A

ankurankan

Right off the assembly line
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

Simply a DIGITian
Staff member
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

Sami Hyypiä, LFC legend
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.
 
Top Bottom