[Tutor] Guess my number game
Brian van den Broek
broek at cc.umanitoba.ca
Fri Dec 16 01:59:30 CET 2005
Pujo Aji said unto the world upon 2005-12-15 14:52:
> your guess still use random.randrange that's make computer doesn't care
> about whether guess is low or higher than your number.
> This code should be like this:
<snip pujo's corrected code>
> Hope this help
> On 12/15/05, William Mhlanga <reddazz at gmail.com> wrote:
>>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,
<snip William's original code>
>>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.
>>Thanks for your help.
I have a suggestion for you: once you get the "guess by random
flailing" approach to work, you might think about ways to try to make
you code live up to the claim "I will try to guess it in as few
attempts as possible.\n" :-)
Right now, if the number is 1, it could take the code 50 tries in the
worst case, even with pujo's suggestion to improve the strategy you
If you get stuck on that, post back.
More information about the Tutor