[Tutor] breaking the 'while' loop

Alexander Kapshuk akap at isd.dp.ua
Tue Mar 20 15:41:26 CET 2007


Dear All,

 

I have been learning computer programming with Python only for a short
while. I have a question to do with breaking the while loop.

 

I have attached the source code of a program called 'Guess my number'
with the while loop running until the right number is guessed.

 

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:

 

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.

 

Regards,

 

Alexander Kapshuk

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070320/4fb44c3b/attachment.htm 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: guess_my_number.py
Type: application/octet-stream
Size: 905 bytes
Desc: guess_my_number.py
Url : http://mail.python.org/pipermail/tutor/attachments/20070320/4fb44c3b/attachment.obj 


More information about the Tutor mailing list