用代码实现方框小游戏

感谢大家收看我的博客。 今日内容,《用代码实现方框小游戏》

所需工具 其他 电脑 什么系统都行 Python 模块:easygui

话不多说, 直接上代码。 干就完了,兄弟们,奥利给!!!

import random,easygui
secret = random.randint(1,100)
guess = 0
tries = 0
easygui.msgbox("""你好,欢迎来到我的猜数游戏,请点击OK,让我们开始吧!""")
while guess != secret and tries < 10:
    guess = easygui.integerbox("请输入你猜的数:")
    if not guess:break
    if guess < secret:
        easygui.msgbox(str(guess)+"太低了,再试一次!")
    elif guess > secret:
        easygui.msgbox(str(guess)+"太高了,再试一次!")
    tries = tries + 1
if guess == secret:
    easygui.msgbox("恭喜你,答对了,你太厉害了!")
else:
    easygui.msgbox("你打错了,下次再努力吧!"+str(secret))
经验分享 程序员 微信小程序 职场和发展