[Tutor] Lists/raw_input

Christian Witts cwitts at compuscan.co.za
Tue Feb 7 07:08:00 CET 2012


On 2012/02/07 07:40 AM, Michael Lewis wrote:
> I want to prompt the user only once to enter 5 numbers. I then want to 
> create a list out of those five numbers. How can I do that?
>
> I know how to do it if I prompt the user 5 different times, but I only 
> want to prompt the user once.
>
> Thanks.
>
> -- 
> Michael
>
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
You can take your input from your user in one line seperated by 
something like a space and then split it after you capture it so for eg.

user_input = raw_input('enter 5 numbers seperated by a space each: ')
list_from_input = user_input.split() # Split by default splits on 
spaces, otherwise you need to specify the delimiter
# Then you can validate the list to ensure all 5 are actually numbers, 
otherwise prompt the user to re-enter them

Hope that help.
-- 

Christian Witts
Python Developer
//
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20120207/62f6d1dd/attachment-0001.html>


More information about the Tutor mailing list