python 笔记5:猜数字游戏

import random

b = 0
# num = random.randint(0, 100)
while b != "q":
    num = random.randint(0, 100)
    print(">>>猜数字游戏开始<<<")
    while 1:
        a = input("请猜数字[0,100]:")
        a = int(a)
        if a == num:
            print("恭喜您猜中,答案是%d" % num)
            b = input("是否结束游戏(结束:q):")
        elif a < num:
            print("您猜的小了,请重新再猜!")
            continue
        elif a > num:
            print("您猜的大了,请重新再猜!")
            continue
        else:
            print("您输入数据有误,为%d" % a)
            continue
        break
print(">>>猜数字游戏结束<<<")

你可能感兴趣的:(程序)