请参考如下例子
import random
times = 3
secret = random.randint(1,10)
print('------------------我爱鱼C工作室------------------')
guess = 0
temp = input("不妨猜一下小甲鱼现在心里想的是哪个数字:\n")
while temp.isdigit() is not True:
temp = input("抱歉,输入不合法,请输入一个整数:")
while (guess != secret) and (times != 0) and (temp.isdigit() is True):
times = times - 1
guess = int(temp)
if guess == secret:
print("我草,你是小甲鱼心里的蛔虫吗?!")
print("哼,猜中了也没有奖励!")
elif guess > secret:
print("哥,大了大了~~~")
temp = input("再试一次吧!:")
else:
print("嘿,小了,小了~~~")
temp = input("再试一次吧!:")
print("没机会啦~~游戏结束,不玩啦^_^")
|