""" 猜数游戏 """
import random
def CaiShu():
"""猜数游戏"""
num = random.randint(1,101)#生成随机数
count = 0#计数器,控制输入次数
print("[1,100] guess game, you have five chances")
while True:
if count > 4:
print("Sorry,You Lose")
break
#异常处理,保证输入的是整数
try:
guess = int(input("Please enter an integer :"))
except:
print("Error")
continue
if num == guess:
print("You Win!!!!")
break
if guess < num:
print("Lower!!")
print("You still have {} chances".format(4-count))
else:
print("Highter!!")
print("You still have {} chances".format(4-count))
count += 1#计数器加1
if __name__ == '__main__':
CaiShu()
还没有评论,来说两句吧...