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&nbsp; <br><br>print &quot;Welcome to 'Guess Your Number'!&quot;<br>print &quot;\nThink of a number between 1 and 100.&quot;<br>print &quot;And I will try and guess it!\n&quot;
<br>print &quot;Valid inputs are: higher, lower and correct.&quot;<br><br>raw_input(&quot;\n\nPress enter once you have thought of a number.&quot;)<br><br><br># set the initial values<br>guess = random.randrange(100) + 1
<br>
tries = 1<br><br><br><br># guessing loop<br>response = &quot;&quot;<br>while response != &quot;correct&quot;:<br>&nbsp;&nbsp;&nbsp; print &quot;Is it&quot; ,guess, &quot;?\n&quot;<br>&nbsp;&nbsp;&nbsp; response = raw_input (&quot;&quot;)<br>&nbsp;&nbsp;&nbsp; if response == &quot;lower&quot;:
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; guess = random.randrange(1, guess)<br>&nbsp;&nbsp;&nbsp; elif response == &quot;higher&quot;:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; guess = random.randrange(guess, 100)<br><br><br># Error message for invalid inputs<br>&nbsp;&nbsp;&nbsp; else:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print &quot;Invalid entry!&quot;
<br><br><br>&nbsp;&nbsp;&nbsp; tries += 1<br><br><br>print &quot;\nI guessed it!&nbsp; The number was&quot;, guess<br>print &quot;And it only took me&quot;, tries, &quot;tries!\n&quot;<br><br>&nbsp;<br>raw_input(&quot;\n\nPress the enter key to exit.&quot;)
<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