猫史档案馆


【Python作品分享】计算机数学题【作业帖】

用户:EmpowerAllEmpowerAll查看:29 回复:0 评论:0 创建时间:2020-02-11T13:23:27


【作品展示】

center_image

 

【作品介绍】

 

【作品源代码】

import random


while True:
    a = int(input('计算机还是数学题?( 1.计算机 2.数学题 (其他数字=随机)(请勿输入非整数))'))
    if (a == 1):
        for __count in range(10):
            c = float(input('第一个数'))
            d = float(input('第二个数'))
            e = input('+-*/')
            if (e == '+'):
                print((c + d))
            elif (e == '-'):
                print((c - d))
            elif (e == '*'):
                print((c * d))
            elif (e == '/'):
                try:
                    print((c / d))
                except ZeroDivisionError:
                    print('除0错误')
            else:
                print('输入运算符错误!')
    elif (a == 2):
        for __count in range(10):
            c = round(random.uniform(0, 100.9),2)
            d = round(random.uniform(0, 100.9),2)
            f = random.randint(1, 4)
            # 1加法 2减法 3乘法 4除法
            if (f == 1):
                g = (c + d)
                expression = (str(c)+'+'+str(d)+'=')
            elif (f == 2):
                g = (c - d)
                expression = (str(c)+'-'+str(d)+'=')
            elif (f == 3):
                g = (c * d)
                expression = (str(c)+'×'+str(d)+'=')
            elif (f == 4):
                g = (c / d)
                expression = (str(c)+'÷'+str(d)+'=')

            h = float(input(expression))
            if (h == g):
                print('答案正确!!')
            else:
                print('回答错误!!')
                print('正确答案',g)
        print('输入错误!')

 

【提示】

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

https://python.codemao.cn


回复

上一页第 1 页 / 共 0 页下一页