猫史档案馆


【Python作品分享】计算小超市【作品秀】

用户:K_FenK_Fen查看:0 回复:0 评论:0 创建时间:2021-04-16T13:57:33


【作品展示】

center_image

 

【作品介绍】

做算术题。。。

 

【作品源代码】

import random

# 答对题数
correctCount = 0
# 已答题数
numberOfQuestion = 0
while (numberOfQuestion < 10):
    number1 = random.randint(0, 6)
    number2 = random.randint(0, 6)
    b = ['+', '-', '×', '÷']
    c = random.choice(b)
    if   (c == '+'):
        ans1 = number1 + number2
    elif (c == '-'):
        ans1 = number1 - number2
    elif (c == '×'):
        ans1 = number1 * number2
    elif (c == '÷'):
        ans1 = number1 / number2
    else:
        pass
    # print(ans1)
    question = (((('请输入:' + str(number1)) + c) + str(number2)) + '=')
    answer = eval((input(question)))
    numberOfQuestion += 1
    if (ans1 == answer):
        correctCount += 1
        anstr = (((((('太棒了!\n' + '   已经答对') + str(correctCount)) + '题\n') + '   一共做答') + str(numberOfQuestion)) + '题')
    else:
        anstr = (((((('要加油哦!\n' + '   当前答对') + str(correctCount)) + '题\n') + '   一共做答') + str(numberOfQuestion)) + '题')
    print("")
    print(anstr)
    print("")

print("")
print("     答题结束")
print("")

 

【提示】

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

https://python.codemao.cn


回复

上一页1 页 / 共 0下一页