E
eli m
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?
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?
This is my code: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: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.
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.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.