
Computer Number Guessing Game
By: a guest on
May 10th, 2012 | syntax:
Python | size: 1.15 KB | hits: 8 | expires: Never
# Number guessing game.
# The computer plays itself, if the number is too high or too low the player is informed.
# If the game takes longer than 10 rounds, it is an automatic lose.
import random
random.seed
CompGuess = random.randint(1,100)
CompPlayer = random.randint(1,100)
print "CompPlayer\'s secret number is " +str(CompPlayer)
LowInt1 = 1
HighInt1 = 100
RoundCount = 1
running = True
while running == True:
print "Round Number : " +str(RoundCount)
if RoundCount == 11:
print "CompPlayer: You took too long, you lose!"
running = False
print "CompGuesser: My guess is " +str(CompGuess)
if CompGuess > CompPlayer:
print 'CompPlayer: Your guess is high'
HighInt1 = CompGuess
CompGuess = random.randint(LowInt1, HighInt1)
print "Range is " +str(LowInt1)+ ' , ' +str(HighInt1)
print CompGuess
if CompGuess < CompPlayer:
print 'CompPlayer: Your guess is low'
LowInt1 = CompGuess
CompGuess = random.randint(LowInt1, HighInt1)
print "Range is " +str(LowInt1)+ ' , ' +str(HighInt1)
print CompGuess
if CompGuess == CompPlayer:
print "CompGuesser: I win! :3"
running = False
RoundCount = RoundCount + 1