用Python写的猜数字程序
#this is a guess the number game.
import random
secretNumber = random.randint(1,20)
print('I am thinking of a number between 1 and 20.')
#ask the player to guess the number 6 times.
for i in range(1,7):
print('Take a guess.')
guess = int(input())
if guess < secretNumber:
print('Your guess is too low.')
elif guess > secretNumber:
print('Your guess is too high.')
else:
break
if guess == secretNumber:
print('Good ! '+str(i) + ' guesses!')
else:
print('Nope.'+str(secretNumber))
I am thinking of a number between 1 and 20.
Take a guess.
4
Your guess is too low.
Take a guess.
16
Your guess is too high.
Take a guess.
134
Your guess is too high.
Take a guess.
9
Good ! 4 guesses!