Hi<br><br>I hope someone can help me!<br><br>I am currently learning
Python using a book by Michael Dawson. In one of the exercises I have
to right a program that will guess a number chosen by the user.<br><br>It
is partly working, however it does not seem to keep state of numbers
that should have already been ruled out as too high or low.
<br><br>Any pointers would be very much appreciated!<br><br>import random <br><br>print "Welcome to 'Guess Your Number'!"<br>print "\nThink of a number between 1 and 100."<br>print "And I will try and guess it!\n"
<br>print "Valid inputs are: higher, lower and correct."<br><br>raw_input("\n\nPress enter once you have thought of a number.")<br><br><br># set the initial values<br>guess = random.randrange(100) + 1
<br>
tries = 1<br><br><br><br># guessing loop<br>response = ""<br>while response != "correct":<br> print "Is it" ,guess, "?\n"<br> response = raw_input ("")<br> if response == "lower":
<br> guess = random.randrange(1, guess)<br> elif response == "higher":<br> guess = random.randrange(guess, 100)<br><br><br># Error message for invalid inputs<br> else:<br> print "Invalid entry!"
<br><br><br> tries += 1<br><br><br>print "\nI guessed it! The number was", guess<br>print "And it only took me", tries, "tries!\n"<br><br> <br>raw_input("\n\nPress the enter key to exit.")
<br clear="all"><br>-- <br>Best Regards<br><span class="sg"><br>Jon</span><br clear="all"><br>-- <br>Best Regards<br><br>Jon Moore