[Tutor] help

Michiel Overtoom motoom at xs4all.nl
Wed Jul 15 23:26:42 CEST 2009


jonathan wallis wrote:

> i cant figure out if there is a way to make so if one loop ends it says 
> something different than if the other loop ends.

Maybe you could use two separate tests and break out of the loop if x or 
y gets too low.
Because the tests are separated you could say something different for 
each case.
For example:

import random

x=y=9
while True:
     print "x is %d, y is %d" % (x,y)
     if x<=0:
         print "Loop stopped because X was too low"
         break
     if y<=0:
         print "Loop stopped because Y was too low"
         break
     # do something with x and y
     if random.random()>0.5:
         x-=1
     else:
         y-=1


-- 
"The ability of the OSS process to collect and harness
the collective IQ of thousands of individuals across
the Internet is simply amazing." - Vinod Valloppillil
http://www.catb.org/~esr/halloween/halloween4.html


More information about the Tutor mailing list