猜数字小游戏

蓝咒 提交于 2020-03-19 19:09:13

3 月,跳不动了?>>>

from random import randint


def guess():
    num_int = randint(0, 10)

    while True:
        user_input = input("what number you guess (1, 10)")

        try:
            user_guess = int(user_input)

            if user_guess == num_int:
                print("u r right, the number is %s" % user_guess)
                break
            elif user_guess < num_int:
                print("the number is greater then yours , do not give up")
            else:
                print("the number is less then yours , do not give up")
        except:
            print("input error")


if __name__ == '__main__':
    guess()

猜0~10 还是比较容易的,如果猜0~100 就麻烦些,可以加入尝试次数的限制,增加可玩性

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!