zoukankan      html  css  js  c++  java
  • 软件工程——自动生成小学四则运算题目

    自动生成小学四则运算题目

    GitHub:https://github.com/asd516970982/BigDaddy/commit/18c874f8c77554b089d19b7e47ffc0d9502b5635

    拿到这份题目,我们首先就得考虑小学生算法的算法范围,一般都是加法、减法、乘法、除法,而且一般不会出现小数,出题也得比较适合这部分年龄段的题目,通过去网上搜集一些出题的类似代码,经过自己的学习,并不断改进代码,让程序变得比较完整。我制作的算法有两个函数,一个负责出题,另一个则负责给出答案。

    PSP表格:

    PSP2.1

    Personal Software Process Stages

    预估耗时(分钟)

    实际耗时(分钟)

    Planning

    计划

     10

    11 

    · Estimate

    · 估计这个任务需要多少时间

     300

    120 

    Development

    开发

     300

    120 

    · Analysis

    · 需求分析 (包括学习新技术)

     /

     /

    · Design Spec

    · 生成设计文档

     /

     /

    · Design Review

    · 设计复审 (和同事审核设计文档)

     /

    · Coding Standard

    · 代码规范 (为目前的开发制定合适的规范)

     /

    · Design

    · 具体设计

     20

    15 

    · Coding

    · 具体编码

     160

    100 

    · Code Review

    · 代码复审

     30

    40 

    · Test

    · 测试(自我测试,修改代码,提交修改)

     30

    40 

    Reporting

    报告

     /

    · Test Report

    · 测试报告

     /

    · Size Measurement

    · 计算工作量

     /

    · Postmortem & Process Improvement Plan

    · 事后总结, 并提出过程改进计划

     /

     /

    合计

      

     300

     120

    代码如下:

    import random
    import profile
     
    #四则运算
     
    def xxsf():
     
        sym = ['', '', '×', '÷']
     
        f= random.randint(0, 3)#用于随机出算法题
     
        n1 = random.randint(1, 100)
     
        n2 = random.randint(1, 100)
     
        result = 0
        yu = 0
        flag = 0
     
        if f== 0:#加法
     
           result  = n1 + n2
     
        elif f == 1:#减法,要先比较大小,防止输出负数
     
            n1, n2 = max(n1, n2), min(n1, n2)
     
            result  = n1 - n2
     
        elif f== 2:#乘法
     
            result  = n1 * n2
     
        elif f == 3:#除法,要比较大小,并循环取整除
     
            n1, n2 = max(n1, n2), min(n1, n2)
     
            result  = int(n1 / n2)
            yu = n1%n2
            flag = 1
     
        print(n1, sym[f], n2, '= ', end='')
     
        return result,yu,flag
     
      
     
    #制作题库
     
    def test():
        sym = ['', '', '×', '÷']
     
        print('输入所需要的题目数量')
     
        n=int(input())
     
        result =[]
        yu = []
        flag = []
     
        m=0
     
        while m<=(n-1):
     
            print(m+1,end='')
            xxsf1 = xxsf()
            result .append(xxsf1[0])
            yu .append(xxsf1[1])
            flag .append(xxsf1[2])
     
            print(' ')
     
            m=m+1
     
        m=0
     
        print('对应的答案:')
     
        while m<=(n-1):
            if flag[m] == 1:
                print(m+1,'',result [m],'   除法余数为:',yu [m])
            else:
                print(m+1,'',result [m])
     
            m=m+1
     
      
    profile.run('xxsf()')#对xxsf函数进行效能分析
    print('
    ')
    profile.run('test()')#对test函数进行效能分析
    print('
    ')
     
    print('选择想要的模式')
     
    print('1、进行四则运算')
     
    print('2、制作题库(可选择模式有:1与2)')
     
    n=int(input())
     
    #当输入1时,进行四则运算,调用函数xxsf()
     
    if n==1:
     
        while True:
            xxsf1 = xxsf()
            result  = xxsf1[0]
            yu  = xxsf1[1]
            flag  = xxsf1[2]
            
            j= input()
            s= int(j)
            
            if flag ==1:
                x = input()
                y = int(x)
                if s== result and y== yu:
     
                    print('right')
     
                else:
     
                    print('error.the answer is', result ,'   余数为:',yu)
            elif flag != 1:
                if s== result:
     
                    print('right')
     
                else:
     
                    print('error.the answer is', result )
     
    #当输入2时,进行制作题库
     
    if n==2:
     
         test()

    运行结果如下:

     

  • 相关阅读:
    redis操作
    MySQL架构
    MySQL查询缓存
    MySQL数据备份与还原
    Sql性能优化
    Notepad++中每一行的开头和结尾添加引号?
    分组聚合
    Python3用scan和delete命令批量清理redis数据
    VUE+django
    python转化13位时间戳
  • 原文地址:https://www.cnblogs.com/asd516970982/p/13702671.html
Copyright © 2011-2022 走看看