The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> Python Programming
|
input( )
Discuss input( ) in the Python Programming forum on Dev Shed. input( ) Python Programming forum discussing coding techniques, tips and tricks, and Zope related information. Python was designed from the ground up to be a completely object-oriented programming language.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

November 1st, 2003, 04:59 PM
|
 |
Only the strong survives!!.
|
|
Join Date: Feb 2003
Location: A World of wonders.
|
|
|
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!"
|

November 1st, 2003, 07:06 PM
|
 |
Hello World :)
|
|
Join Date: Mar 2003
Location: Hull, UK
|
|
|
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
|

November 2nd, 2003, 12:10 AM
|
 |
Only the strong survives!!.
|
|
Join Date: Feb 2003
Location: A World of wonders.
|
|
|
yes thanx.. the raw_input worked for me.. but what is the diffrence? =)
|

November 2nd, 2003, 02:04 AM
|
|
Contributing User
|
|
Join Date: Jul 2003
Posts: 133
Time spent in forums: < 1 sec
Reputation Power: 10
|
|
|
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.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|