Using Loops to track user input

Michele Simionato mis6 at pitt.edu
Mon Jul 7 18:46:05 EDT 2003


hokiegal99 <hokiegal99 at hotmail.com> wrote in message news:<beaeoj$jo4$1 at solaris.cc.vt.edu>...
> Perl's motto is "there's more than one way to do it," right? Well, after 
> reading all of these responses, I think Python could make the same 
> claim. Thanks again guys!
> 
> 
> Bob Gailer wrote:
> 
> > Not to neglect the 1-liner:
> > 
> > import operator; reduce(operator.add,[int(raw_input("Number>")) for i in 
> > range(10)])
> > 
> > Bob Gailer
> > bgailer at alum.rpi.edu
> > 303 442 2625

Nowadays even shorter:

sum([int(raw_input("Number>")) for i in range(10)])

;)




More information about the Python-list mailing list