Guess My Number Game

F. GEIGER fgeiger at datec.at
Sat May 15 11:36:04 EDT 2004


*Many* years ago I owned a TI 58C pocket calculator (anyone remember
these?). It had the game you speak about built into its rom. It used
bisection: You had to choose a number and than tell the computer if the
number it guessed was less than or greater than or equal the one you had
chosen.

Cheers
Franz GEIGER


"EAS" <eriksp at attbi.nospam.com> schrieb im Newsbeitrag
news:u9ppc.5447$gr.390828 at attbi_s52...
> Hey, I'm new to python (and programming in general) so I'll prolly be
around
> here a lot...
>
> Anyways, I've found out how to make a "guess my number game" where the
> player guesses a number between 1 and 100, but I want to switch things
> around. I want to be able to put in my own number and have the computer
> guess it. I already know how to make it guess (by using randrange) but I'm
> having a hard time making it smarter. (Like guessing higher or lower based
> on what it's told it needs to do.) Here's the code I have right now:
>
> __________________________________________________________
>
>
> import random
>
> guess = 0
> tries = 0
> number = input("Pick a number between 1 and 100 for the computer to guess:
> ")
>
> while number > 100 or number < 1:
> number = input("Pick a number between 1 and 100 for the computer to guess:
> ")
>
> while guess != number:
> guess = random.randrange(101)
> print "The computer guessed", guess
> tries += 1
> past = guess
> while guess < number:
> guess = random.randrange(guess, 101)
> print "The computer guessed", guess
> tries += 1
> while guess > number:
> guess = random.randrange(0, guess)
> print "The computer guessed", guess
> tries += 1
>
> print "The computer guessed your number after", tries, "tries."
>
> raw_input("Press enter to exit.")
>
> ____________________________________________________________
>
>
> As you can see, I've already made it a little smarter but I think I could
> still mae it better. Any ideas?
>
> Also, does anyone know a really popular python forum?
>
>





More information about the Python-list mailing list