E
EAS
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?
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?