[Tutor] help

Alan Gauld alan.gauld at btinternet.com
Thu Jul 16 23:32:06 CEST 2009


"jonathan wallis" <mindboggler12 at gmail.com> wrote 

>i have a duel loop that looks like this            
> 
> while y > 0 and x > 0:

This is not any kind of loop its a while expression.
It should have a body and that would then constitute 
a single while loop not a dual loop ( a duel lop has 
something to do with repeatedly settling matters of 
honor! :-)

> 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.

I'm not certain what you mean by that but I assume 
you mean you want to determine which variable 
went out of bounds?

If so you can use the else clause of a while loop:

while x > 0 and y > 0:
     choice = raw_input('x or y?')
     if choice == 'x': x = 0
     else: y = 0
else:
    if x <= 0: print 'it was x'
    else: print 'it was y'


HTH,


-- 
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/



More information about the Tutor mailing list