Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #38896

Re: How would you do this?

Newsgroups comp.lang.python
Date 2013-02-14 16:19 -0800
References <58be0de9-e39e-4b95-99da-d8eb3270db33@googlegroups.com> <mailman.1790.1360887006.2939.python-list@python.org>
Message-ID <3df34331-509e-4186-bab1-1d4536bc521f@googlegroups.com> (permalink)
Subject Re: How would you do this?
From eli m <techgeek201@gmail.com>

Show all headers | View raw


On Thursday, February 14, 2013 4:09:37 PM UTC-8, Oscar Benjamin wrote:
> On 14 February 2013 23:34, eli m <techgeek201@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. 
        

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

How would you do this? eli m <techgeek201@gmail.com> - 2013-02-14 15:34 -0800
  Re: How would you do this? Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2013-02-15 00:09 +0000
    Re: How would you do this? eli m <techgeek201@gmail.com> - 2013-02-14 16:19 -0800
    Re: How would you do this? eli m <techgeek201@gmail.com> - 2013-02-14 16:19 -0800
      Re: How would you do this? vduncan80@gmail.com - 2013-02-15 11:17 -0800
      Re: How would you do this? vduncan80@gmail.com - 2013-02-15 11:17 -0800

csiph-web