好了,还给你加了个最后显示正确答案的效果import random
times = 3
secret = random. randint(1,10)
print('猜了个数')
guess = 0
print ("猜一下我在想哪个数字:", end=" ")
while (guess != secret) and (times > 0):
temp = input()
guess = int(temp)
times = times -1
if guess == secret:
print("猜对了")
print("没有奖励")
else:
if guess > secret:
print("猜大了")
if times == 0:
print("机会用光咯,正确答案:" + str(secret))
break
print("再试一次吧!注意你还有" + str(times) + "次机会",end = "")
else:
print("猜小了")
if times == 0:
print("机会用光咯,正确答案:" + str(secret))
break
print("再试一次吧!注意你还有" + str(times) + "次机会:",end = "")
print("Game Over")
|