5. 小甲鱼猜数字程序优化
import random;times = 3
#random.randint表示模块中的随机数
secret = random.randint(1,10)
temp = input("不妨猜一下小甲鱼心里想的数字:")
guess = int(temp)
while (guess != secret) and (times > 0):
temp = input("哎呀,猜错了,请重新输入吧:")
guess = int(temp)
times = times - 1
if guess == secret:
print("你是小甲鱼心里的蛔虫么?")
else:
if guess > secret:
print("哥,大了大了")
else:
print("小了小了")
if times > 0:
print("再试一次吧:")
else:
print("机会用光咯")
print("游戏结束!"s)