Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
AT&T devCentral & BlackBerry(r) Webcast Series: BlackBerry and GPS -Build Location Awareness into your BlackBerry Applications, July 10th-1:00PM EST. Register Today!
  #1  
Old November 1st, 2003, 04:59 PM
xlordt's Avatar
xlordt xlordt is offline
Only the strong survives!!.
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: Feb 2003
Location: A World of wonder.
Posts: 5,537 xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)  Folding Points: 108660 Folding Title: Super Ultimate Folder - Level 1Folding Points: 108660 Folding Title: Super Ultimate Folder - Level 1Folding Points: 108660 Folding Title: Super Ultimate Folder - Level 1Folding Points: 108660 Folding Title: Super Ultimate Folder - Level 1Folding Points: 108660 Folding Title: Super Ultimate Folder - Level 1Folding Points: 108660 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 4 Weeks 1 Day 21 h 42 m
Reputation Power: 378
Send a message via ICQ to xlordt Send a message via AIM to xlordt Send a message via MSN to xlordt Send a message via Yahoo to xlordt Send a message via Google Talk to xlordt Send a message via Skype to xlordt
Facebook
input( )

Ok i started learning python last night so bear with me here...

The following code works.. but there is one problem
when i enter 1 or 2 i get what i programed it to do.. but if i was to just hit enter.. the program gives me an error as follow

File "./p.py", line 7, in ?
I = input( "> " )
File "<string>", line 0

^
SyntaxError: unexpected EOF while parsing

Code:

start  =  ["Starting Python..", "Python started!", "Python ended!"]


print "What would you like to do?\n1: Start program\n2: End program\n"

I = input( "> " )

if I == 1:
  print "\n",start[0],"\n",start[1],"\n",
  
elif I == 2:
  print "\n",start[2],"\n" 
  
else:
  print "Hey enter the damn number man!" 

Reply With Quote
  #2  
Old November 1st, 2003, 07:06 PM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,529 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 17 h 19 m 5 sec
Reputation Power: 63
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
Hi xlordt, Firstly welcome to the Python board. Always nice to see a new face!

Anyway what your looking for here is the raw_input(prompt) function.. input(prompt) not only takes user input but evaluates it as a Python expression i.e. the following Python shell example..

>>> input('Enter an Expression to be evaulated: ')
Enter an Expression to be evaulated:
1 + 1
2
>>> raw_input('Enter an Expression to be evaulated: ')
Enter an Expression to be evaulated:
1 + 1
'1 + 1'
>>>

Hope this helps,
Mark.
__________________
programming language development: www.netytan.com Hula


Reply With Quote
  #3  
Old November 2nd, 2003, 12:10 AM
xlordt's Avatar
xlordt xlordt is offline
Only the strong survives!!.
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: Feb 2003
Location: A World of wonder.
Posts: 5,537 xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)  Folding Points: 108660 Folding Title: Super Ultimate Folder - Level 1Folding Points: 108660 Folding Title: Super Ultimate Folder - Level 1Folding Points: 108660 Folding Title: Super Ultimate Folder - Level 1Folding Points: 108660 Folding Title: Super Ultimate Folder - Level 1Folding Points: 108660 Folding Title: Super Ultimate Folder - Level 1Folding Points: 108660 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 4 Weeks 1 Day 21 h 42 m
Reputation Power: 378
Send a message via ICQ to xlordt Send a message via AIM to xlordt Send a message via MSN to xlordt Send a message via Yahoo to xlordt Send a message via Google Talk to xlordt Send a message via Skype to xlordt
Facebook
yes thanx.. the raw_input worked for me.. but what is the diffrence? =)

Reply With Quote
  #4  
Old November 2nd, 2003, 02:04 AM
percivall percivall is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 133 percivall User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
As Netytan said, the difference is that, while raw_input() stores a string, input() not only stores the string, but also evaluates it.

If I would enter "1+1" when prompted by raw_input(), the result would be "1+1". If I entered the same string when prompted by input(), it would store 2 (note the lack of quotes).

Last edited by percivall : November 2nd, 2003 at 02:11 AM.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > input( )


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway