[Tutor] breaking the 'while' loop

Luke Paireepinart rabidpoobear at gmail.com
Tue Mar 20 16:59:21 CET 2007


>
>
> I want to limit the number of tries to 5. To do that, I have tried the 
> /_if structure_/ along with the /_break statement_/ immediately below the
>
> ‘tries += 1’ line:
>
Or you could just add this condition to the while loop.
while (guess != the_number and tries < 6):
>
> if tries > 5:
>
> break
>
> print “Wrong guess!”
>
> Which still did not result in the /_while loop_/ breaking after 
> attempt No 5.
>
> I would appreciate being explained what I am doing wrong.
>
You should have included the source that didn't work. It does us no good 
to see working code that doesn't do what you want.


More information about the Tutor mailing list