我是靠谱客的博主 甜蜜天空,这篇文章主要介绍随机函数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,"次")

最后

以上就是甜蜜天空最近收集整理的关于随机函数random小游戏——猜大小的全部内容,更多相关随机函数random小游戏——猜大小内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(137)

评论列表共有 0 条评论

立即
投稿
返回
顶部