[Tutor] How to take in 2 or more values from user on a single line (like parameters?)

Michael Langford mlangford.cs03 at gtalumni.org
Wed Sep 19 23:00:17 CEST 2007


Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit (Intel)] on
wi
32
Type "help", "copyright", "credits" or "license" for more information.
>>> a = raw_input("Who's yo daddy?: ")
Who's yo daddy?: Bubby June
>>> print a
Bubby June
>>>

See how the variable "a" now has the whole sentence "Bubby June" in it? You
can call split on "a" now and you'll get a list of words:

>>> Names = a.split()
>>> print Names
['Bubby','June']
>>>

       --Michael

On 9/19/07, Boykie Mackay <boykie.mackay at gmail.com> wrote:
>
> Hi again,
>
> I have racked my brains and tried googling but to no avail.
>
> Is there any simple way of getting parameter input from the user?
>
> What I want to do is to type in two (or more) values on the command
> prompt and have a function do some work on them and return a result.For
> example say I had a multiplication function that I wanted to work as
> follows:
>
> me at computer:~/dir/project$python multiply.py
> me at computer:~/dir/project$10 12 [enter]
> me at computer:~/dir/project$120
>
> Basically I want to start the program 'multiply.py',then be presented
> with a blank screen in which I enter the numbers I want multipied
> seperated by a space e.g 1 10 11 to give an answer of 110.I have used
> the raw_input() and input() functions but it seems they only take on
> value at a time!
>
> I suppose what I'm really asking is how to receive muliple values of
> input from a user on a single line?
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>



-- 
Michael Langford
Phone: 404-386-0495
Consulting: http://www.TierOneDesign.com/
Entertaining: http://www.ThisIsYourCruiseDirectorSpeaking.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070919/a0160d37/attachment-0001.htm 


More information about the Tutor mailing list