import random
answer = random.randint(1,15)
chance = 5 #次数
integral = 20 #积分
while chance:
try:
number = int(input("猜一猜(1-20)\n"))
except ValueError:
print("请输入数字")
else:
if number == answer:
integral += 5
print("猜对了")
break
elif number > answer:
chance -= 1
integral -= 5
print("大了\n")
elif number < answer:
chance -= 1
integral -= 5
print("小了\n")
print("余剩积分",integral)
if chance == 0:
print("错误次数过多休息一会吧")
python猜数字游戏代码
最新推荐文章于 2024-07-23 23:55:54 发布