|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
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
|
||||
|
||||
|
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!"
__________________
IE QUOTE | PHP Manual | Google | C/C++ Compiler | Linux Tutorials | General Stuff Game Dev |
|
#2
|
||||
|
||||
|
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. |
|
#3
|
||||
|
||||
|
yes thanx.. the raw_input worked for me.. but what is the diffrence? =)
|
|
#4
|
|||
|
|||
|
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. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Python Programming > input( ) |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|