随机函数random小游戏——猜大小

 
"""
猜数游戏
"""
i = 1
count = random.choice(range(101))
#print(count)
num = float(input("请输入你猜的数:"))
while num != count:
    while num > 100:
        num = float(input("不在范围内请重新输入:"))
        i += 1
    while num < 101:
        if count < num:
            num = float(input("你猜大了!请重猜:"))
            i += 1
        elif count > num:
            num = float(input("你猜小了!请重猜:"))
            i += 1
        else:
            break
else:
    print("恭喜你猜对了!随机数为",count,"猜了",i,"次")

你可能感兴趣的:(Python)