Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #38897
| 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> |
| Subject | Re: How would you do this? |
| From | eli m <techgeek201@gmail.com> |
| Message-ID | <mailman.1792.1360890057.2939.python-list@python.org> (permalink) |
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 | Next — Previous in thread | Next in thread | Find similar | Unroll 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