猫史档案馆


【Python作品分享】猜数字

用户:114KU5N14114KU5N14查看:0 回复:0 评论:0 创建时间:2021-01-16T17:23:08


【作品展示】

center_image

 

【作品介绍】

啦啦啦啦猜不对

 

【作品源代码】

import random
import easygui
import random, easygui


secret = random.randint(1, 100)
tries = 0
easygui.msgbox('现在开始猜数字,数字的范围是1-100')
temp = easygui.integerbox("请输入一个数字:")
guess = int(temp)

if (guess == secret):
    easygui.msgbox('恭喜你一次就猜对了!')
else:
    if (guess < secret):
        easygui.msgbox('猜小了!')
    else:
        easygui.msgbox('猜大了!')

while (guess != secret and tries < 15):
    temp = easygui.integerbox("猜错了,重新猜猜吧:")
    guess = int(temp)
    tries += 1
    if (guess == secret):
        easygui.msgbox('恭喜您,猜对啦!')
    else:
        if (guess < secret):
            easygui.msgbox('猜小了!')
        else:
            easygui.msgbox('猜大了')
    while (tries >= 50):
        easygui.msgbox('没有机会了')
        break
easygui.msgbox(('哈哈,正确数字是' + str(secret)))

 

【提示】

部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:

https://python.codemao.cn


回复

上一页1 页 / 共 0下一页