<p>If the guess is larger than the number, your code will never prompt for a new guess in the while loop. Try removing one indent on the input() line.</p>
<p><blockquote type="cite">On Sep 24, 2011 10:44 AM, "Cameron Macleod" <<a href="mailto:cmacleod170@gmail.com">cmacleod170@gmail.com</a>> wrote:<br><br>Hi,<br><br>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. Thanks<br>
<br>=======================<br><br>import random<br><br>print("\tWelcome to 'Guess my Number'!")<br>print("\nI'm thinking of a number between 1 and 100.")<br>print("Try to guess it in as few attempts as possible.\n")<br>
<br>#set the initial values<br>the_number = random.randint(1, 100)<br>guess = int(input("Take a guess: "))<br>tries = 1<br><br># guessing loop<br>while guess != the_number:<br> if guess > the_number:<br> print("Lower...")<br>
else:<br> print("Higher...")<br><br> guess = int(input("Take a guess: "))<br> tries += 1<br><br>print("You guessed it! The number was", the_number)<br>print("And it only took you", tries, "tries!\n")<br>
<br>if tries <= 5:<br> print("I didn't know roadrunners could type!")<br>elif tries >= 99:<br> print("P'raps 'Only' wasn't the right word...")<br>elif tries == 100:<br>
print("0_0 You are the unluckiest person in the world. Or the stupidest...")<br>
<br>input("\n\nPress the enter key to exit.")<br><br><div style="padding:0px;margin-left:0px;margin-top:0px;overflow:hidden;word-wrap:break-word;color:black;font-size:10px;text-align:left;line-height:130%">
</div>
<br>_______________________________________________<br>
Tutor maillist - <a href="mailto:Tutor@python.org">Tutor@python.org</a><br>
To unsubscribe or change subscription options:<br>
<a href="http://mail.python.org/mailman/listinfo/tutor" target="_blank">http://mail.python.org/mailman/listinfo/tutor</a><br>
<br></blockquote></p>