Re: How to get 4 numbers from the user in one line for easycomparision?
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.python archive

Re: How to get 4 numbers from the user in one line for easycomparision?

From: George Sakkis <gsakkis@rutgers.edu>
Date: Sun Jul 03 2005 - 17:25:49 CEST

"Alan G" <alan.gauld@freenet.co.uk> wrote:

> > I .... Just need to figure out how to get 4 numbers from
> > the player on one line for easy comparison,
>
> Unless there is a set of batteries somewhere that I don't know
> about I think you have to rely on reading the line as a string
> and then splitting it.
>
> line = raw_input('Type 4 numbers separated by spaces: ')
> numbers = [int(n) for n in line.split(' ')]

Or if you want to assign these 4 numbers to separate variables, you can
use tuple unpacking:

a,b,c,d = map(int, raw_input('Type 4 numbers separated '
                             'by spaces:').split())

If you want to do error handling later, you may need to split this line
into two steps so that you can distinguish between invalid values and
wrong count of values (less or more than 4).

George
Received on Thu Sep 29 16:43:35 2005