newb Q

Steffen Ries steffen.ries at sympatico.ca
Tue Jul 25 07:48:21 EDT 2000


Toy <gee308 at mediaone.net> writes:

> How do you make a section of code repeat X times?
> say I want someone to quess something, but they put it in wrong(i.e.
> nums instead of letters) then after X tries, the prog quits out?
>

repeat=X
while repeat>0:
    repeat = repeat-1 

    # ask your question
    if answer_is_ok:
        break
else:
    raise "Did not get an answer"

instead/additional to the else-clause you can check the value of
"repeat" after the loop:

if repeat <= 0:
    # no valid answer given...

hth,
/steffen
-- 
steffen.ries at sympatico.ca	<> Gravity is a myth -- the Earth sucks!



More information about the Python-list mailing list