Forum     

Go Back   Digit Technology Discussion Forum > Software > Programming
Register FAQ Calendar Mark Forums Read

Programming The destination for developers - C, C++, Java, Python and the lot


Reply
 
LinkBack Thread Tools Display Modes
Old 13-05-2011, 07:07 PM   #1 (permalink)
Right Off the Assembly Line
 
Join Date: May 2011
Posts: 6
Default Problem with Python Shell


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
ankurankan is offline   Reply With Quote
Advertisements. Register and be a member of the community to get rid of them.
Advertisement

Old 13-05-2011, 08:27 PM   #2 (permalink)
Simply a DIGITian
 
krishnandu.sarkar's Avatar
 
Join Date: Nov 2007
Location: Kolkata
Posts: 2,942
Default Re: Problem with Python Shell

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..


Uploaded with ImageShack.us


Anyway...Read Docs carefully again..!! http://docs.python.org/py3k/tutorial/introduction.html
__________________
  • Read The Forum RULES First.
  • Before PM'ing Or Asking Any Questions To Any Mod Read The FAQ's
  • Before Starting A New Thread Read The STICKY THREADS First
  • Before Participating In Bazaar Section Read The BAZAAR RULES
krishnandu.sarkar is online now   Reply With Quote
Old 13-05-2011, 09:48 PM   #3 (permalink)
Right Off the Assembly Line
 
Join Date: May 2011
Posts: 6
Default Re: Problem with Python Shell

thanks....
ankurankan is offline   Reply With Quote
Old 14-05-2011, 08:18 AM   #4 (permalink)
Simply a DIGITian
 
krishnandu.sarkar's Avatar
 
Join Date: Nov 2007
Location: Kolkata
Posts: 2,942
Default Re: Problem with Python Shell

You are welcome

Happy Coding
__________________
  • Read The Forum RULES First.
  • Before PM'ing Or Asking Any Questions To Any Mod Read The FAQ's
  • Before Starting A New Thread Read The STICKY THREADS First
  • Before Participating In Bazaar Section Read The BAZAAR RULES
krishnandu.sarkar is online now   Reply With Quote
Old 14-05-2011, 12:59 PM   #5 (permalink)
NULL_PTR
 
Join Date: Jan 2006
Location: Dangling Pointer
Posts: 88
Default Re: Problem with Python Shell

you are using python 3.x shell but your syntax is of 2.x series
__________________
Writing Mine Own Os
Wanna Join Pm ME
umeshtangnu is offline   Reply With Quote
Old 17-05-2011, 10:12 PM   #6 (permalink)
Right Off the Assembly Line
 
Join Date: May 2011
Posts: 6
Default Re: Problem with Python Shell

Now I am having problem with the else statement


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

SyntaxError: invalid syntax
>>>
ankurankan is offline   Reply With Quote
Old 17-05-2011, 10:19 PM   #7 (permalink)
Simply a DIGITian
 
krishnandu.sarkar's Avatar
 
Join Date: Nov 2007
Location: Kolkata
Posts: 2,942
Default Re: Problem with Python Shell

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.



Uploaded with ImageShack.us
__________________
  • Read The Forum RULES First.
  • Before PM'ing Or Asking Any Questions To Any Mod Read The FAQ's
  • Before Starting A New Thread Read The STICKY THREADS First
  • Before Participating In Bazaar Section Read The BAZAAR RULES
krishnandu.sarkar is online now   Reply With Quote
Old 17-05-2011, 10:56 PM   #8 (permalink)
Sami Hyypiä, LFC legend
 
Liverpool_fan's Avatar
 
Join Date: Jun 2007
Location: Нью-Дели
Posts: 2,138
Default Re: Problem with Python Shell

Quote:
Originally Posted by ankurankan View Post
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.
__________________
Experience true education in Computer Science - http://www.udacity.com | http://www.coursera.org

Spoiler:
Read before asking / messaging any moderator for any query: FAQ + answers for new members

Read all the sticky threads before asking any type of query. Most basic questions are answered in those.
Don't use forum for chatting. Visit http://webchat.freenode.net/?channels=krow, enter nick and connect.
Liverpool_fan is offline   Reply With Quote
Old 17-05-2011, 11:31 PM   #9 (permalink)
Simply a DIGITian
 
krishnandu.sarkar's Avatar
 
Join Date: Nov 2007
Location: Kolkata
Posts: 2,942
Default Re: Problem with Python Shell

^^Yup, and his if syntax is also wrong.
__________________
  • Read The Forum RULES First.
  • Before PM'ing Or Asking Any Questions To Any Mod Read The FAQ's
  • Before Starting A New Thread Read The STICKY THREADS First
  • Before Participating In Bazaar Section Read The BAZAAR RULES
krishnandu.sarkar is online now   Reply With Quote
Old 18-05-2011, 03:26 PM   #10 (permalink)
Alpha Geek
 
Join Date: Jan 2007
Location: In your hearts
Posts: 828
Default Re: Problem with Python Shell

run IDLE, python shell in it will automatically indent the statements.
abhijangda is online now   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


 
Latest Threads
- by Charan
- by Sarath
- by clmlbx

Advertisement




All times are GMT +5.5. The time now is 12:28 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.

Search Engine Optimization by vBSEO 3.3.2