How would you do this?

eli m techgeek201 at gmail.com
Thu Feb 14 19:19:51 EST 2013


On Thursday, February 14, 2013 4:09:37 PM UTC-8, Oscar Benjamin wrote:
> On 14 February 2013 23:34, eli m <techgeek201 at gmail.com> wrote:
> 
> > I want to make a guess the number game (Which i have), but i want to make the computer play the game against itself. How would i do this?
> 
> 
> 
> Your question would make more sense if you would show your program and
> 
> also explain how you would like the output to look when the computer
> 
> played itself.
> 
> 
> 
> 
> 
> Oscar
This is my code:

#Guess the number game
import random
run = 0
while run == 0:
    print ("I am thinking of a number between 1 and 100")
    num = random.randint(1, 100)
    num = int(num)
    guesses = 0
    guessestaken = 0
    while guesses == 0:
        try:
            guess = raw_input("Your guess:")
            guess = int(guess)
            guessestaken = (guessestaken) + 1
            guessestaken = int(guessestaken)
            if guess == (num):
                print 'Correct! It took you', int(guessestaken), 'guesses!'
                playagain = raw_input("Do you want to play again?")
                if playagain == "yes":
                    guesses = 1
                if playagain == "no":
                    run = 1
            if guess > num:
                print ("My number is lower")
            if guess < num:
                print ("My number is higher")
        except TypeError, err:
            print ("Not a valid number")
            
I would like it to show the computer guessing the numbers. 
        



More information about the Python-list mailing list