[Tutor] Infinite Loop

Alan Gauld alan.gauld at btinternet.com
Sat Sep 24 18:48:38 CEST 2011

On 24/09/11 15:43, Cameron Macleod wrote:
> Hi,
> I've been trying to code a simple guess my number game as a starter
> programming project but I've generated an infinite loop accidentally.
> Since I'm new to programming in general, I can't really figure out
> what's causing it.

Nehal told you how to fix it but didn't explain why.

You have the input() call indented to the same level as the else block 
so it only gets executed as part of that block. If the guessed number is 
greater than the target the loop repeats infinitely.

By moving the input() line out you get a new number each time.


Alan G
Author of the Learn to Program web site

More information about the Tutor mailing list