Hi, <br>your guess still use random.randrange that's make computer doesn't care about whether guess is low or higher than your number.<br><br>This code should be like this:<br>&nbsp;&nbsp;&nbsp; print &quot;\t\t\tWelcome to \&quot;Guess My Number\&quot;!&quot;
<br>&nbsp;&nbsp;&nbsp; print &quot;\nThink of a number between 1 and 50.&quot;<br>&nbsp;&nbsp;&nbsp; print &quot;I will try to guess it in as few attempts as possible.\n&quot;<br><br>&nbsp;&nbsp;&nbsp; number = input (&quot;Enter the number: &quot;)<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; #the computer guesses the number using the random function
<br>&nbsp;&nbsp;&nbsp; guess = random.randrange (50) + 1<br>&nbsp;&nbsp;&nbsp; tries = 1<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; #FIXME<br>&nbsp;&nbsp;&nbsp; while (guess != number):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (guess &gt; number):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print &quot;You chose&quot;, guess, &quot;the number is Lower ...&quot;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; guess = random.randint(1, guess-1)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print &quot;You chose&quot;, guess, &quot;the number is Higher ...&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; guess = random.randint(guess+1, 50)
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; tries += 1<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; print &quot;You guessed it! The number was&quot;, number<br>&nbsp;&nbsp;&nbsp; print &quot;And it only took you&quot;, tries, &quot;tries!\n&quot;<br><br>&nbsp;&nbsp;&nbsp; raw_input (&quot;Press &lt;ENTER&gt; to exit.&quot;)
<br><br>Hope this help<br><br>pujo<br><br><div><span class="gmail_quote">On 12/15/05, <b class="gmail_sendername">William Mhlanga</b> &lt;<a href="mailto:reddazz@gmail.com">reddazz@gmail.com</a>&gt; wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
I have been trying to write a guess my number game (using Michael Dawsons book), where the computer guesses the number that I thought of. Here is my code so far,<br><div style="text-align: left;">#The Guess My Number Game
<br>
#<br>#The computer picks a random number between 1 and 50<br>#The player tries to guess it and the computer lets<br>#the player know if the guess is too high, too low<br>#or right on the money<br>#If the player fails to guess the number after 5 tries
<br>#the game ends and the computer prints a chastising message<br>#<br><br>print &quot;\t\t\tWelcome to \&quot;Guess My Number\&quot;!&quot;<br>import random<br><br>print &quot;\nThink of a number between 1 and 50.&quot;
<br>print &quot;I will try to guess it in as few attempts as possible.\n&quot;<br><br>number = input (&quot;Enter the number: &quot;)<br><br>#the computer guesses the number using the random function<br>guess = random.randrange

 (50) + 1<br>tries = 1<br><br>#FIXME<br>while (guess != number):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (guess &gt; number):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print &quot;You chose&quot;, guess, &quot;the number is Lower ...&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print &quot;You chose&quot;, guess, &quot;the number is Higher ...&quot;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; guess = random.randrange (50) + 1<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; tries += 1<br><br>print &quot;You guessed it! The number was&quot;, number<br>print &quot;And it only took you&quot;, tries, &quot;tries!\n&quot;<br><br>raw_input (&quot;Press &lt;ENTER&gt; to exit.&quot;)
<br><br>The program works ok, but the computer sometimes repeats the same numbers when asked to guess. How can I rewrite it so that it guesses like what a human being does i.e. if the number is less than 20, you do not guess numbers above 20.
<br><br>Thanks for your help.<br></div>

<br>_______________________________________________<br>Tutor maillist &nbsp;- &nbsp;<a onclick="return top.js.OpenExtLink(window,event,this)" href="mailto:Tutor@python.org">Tutor@python.org</a><br><a onclick="return top.js.OpenExtLink(window,event,this)" href="http://mail.python.org/mailman/listinfo/tutor" target="_blank">
http://mail.python.org/mailman/listinfo/tutor</a><br><br><br></blockquote></div><br>