其他分享
首页 > 其他分享> > 基于CMMI的软件工程及实训指导—学习笔记(三)

基于CMMI的软件工程及实训指导—学习笔记(三)

作者:互联网

今天我们的任务是:自动生成小学四则运算题目,除了整数外,还要支持真分数的四则运算。

一、项目要求

具体要求:http://yz.yzhiliao.com/course/55/task/326/show

二、项目代码

将代码放到github上方便管理:https://github.com/eLiO-FanG/-/blob/master/Arithmetic

三、项目管理

(一)预估时间

在开始实现程序之前,先用PSP表格记录下估计将在程序的各个模块开发上耗费的时间。

(二)解题思路描述 

(三)设计实现过程

 

(四)代码说明

 1 def Arithmetic6():#五年级以上加了分数相乘除
 2     sign=['+','-','×','÷','×','÷']
 3     s=random.randint(0,5)
 4     num1=random.randint(1,199)
 5     num2=random.randint(1,99)
 6     num3=random.randint(1,20)
 7     num4=random.randint(1,20)
 8     num5=random.randint(1,20)
 9     num6=random.randint(1,20)
10     result=0
11     if s==0:#加法
12         result=num1+num2
13     elif s==1:#减法
14         num1, num2 = max(num1, num2), min(num1, num2)
15         result=num1-num2
16     elif s==2:#乘法
17         num1=Fraction(num3,num4)
18         num2=Fraction(num5,num6)
19         result=num1*num2
20     elif s==3:#除法
21         num1=Fraction(num3,num4)
22         num2=Fraction(num5,num6)
23         result=num1/num2
24     elif s==4:
25         result=num1*num2
26     elif s==5:
27         result=num1/num2
28     print('问题是:',num1,sign[s],num2,'= ',end='')
29     return result
View Code

 

 1 if N==6:
 2 
 3     while (n>0):
 4 
 5         n-=1
 6 
 7         print('------------------------------------')
 8 
 9         result=Arithmetic6()
10 
11         InputResult=input()
12 
13         Input=InputResult
14 
15         if Input==result:
16 
17             print('回答正确')
18 
19         else:
20 
21             print('回答错误,正确答案是:',result)
View Code

 

(五)测试运行

 

 

(六)性能分析

 这里我们用的是profile实现的性能测试。主要测试结果细则如下:

测试结果(较多):

profile.run('Arithmetic1()')
问题是: 6 + 3 =          162 function calls in 0.000 seconds

   Ordered by: standard name

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
       11    0.000    0.000    0.000    0.000 :0(acquire)
       11    0.000    0.000    0.000    0.000 :0(append)
        3    0.000    0.000    0.000    0.000 :0(bit_length)
        1    0.000    0.000    0.000    0.000 :0(exec)
       10    0.000    0.000    0.000    0.000 :0(getpid)
        6    0.000    0.000    0.000    0.000 :0(getrandbits)
       10    0.000    0.000    0.000    0.000 :0(isinstance)
        1    0.000    0.000    0.000    0.000 :0(print)
        1    0.000    0.000    0.000    0.000 :0(setprofile)
        1    0.000    0.000    0.000    0.000 <string>:1(<module>)
        1    0.000    0.000    0.000    0.000 Arithmetic.py:11(Arithmetic1)
       11    0.000    0.000    0.000    0.000 iostream.py:195(schedule)
       10    0.000    0.000    0.000    0.000 iostream.py:307(_is_master_process)
       10    0.000    0.000    0.000    0.000 iostream.py:320(_schedule_flush)
       10    0.000    0.000    0.000    0.000 iostream.py:382(write)
       11    0.000    0.000    0.000    0.000 iostream.py:93(_event_pipe)
        1    0.000    0.000    0.000    0.000 profile:0(Arithmetic1())
        0    0.000             0.000          profile:0(profiler)
        3    0.000    0.000    0.000    0.000 random.py:174(randrange)
        3    0.000    0.000    0.000    0.000 random.py:218(randint)
        3    0.000    0.000    0.000    0.000 random.py:224(_randbelow)
       11    0.000    0.000    0.000    0.000 socket.py:337(send)
       11    0.000    0.000    0.000    0.000 threading.py:1038(_wait_for_tstate_lock)
       11    0.000    0.000    0.000    0.000 threading.py:1080(is_alive)
       11    0.000    0.000    0.000    0.000 threading.py:507(is_set)

profile.run('Arithmetic2()')
问题是: 7 × 10 =          161 function calls in 0.000 seconds

   Ordered by: standard name

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
       11    0.000    0.000    0.000    0.000 :0(acquire)
       11    0.000    0.000    0.000    0.000 :0(append)
        3    0.000    0.000    0.000    0.000 :0(bit_length)
        1    0.000    0.000    0.000    0.000 :0(exec)
       10    0.000    0.000    0.000    0.000 :0(getpid)
        5    0.000    0.000    0.000    0.000 :0(getrandbits)
       10    0.000    0.000    0.000    0.000 :0(isinstance)
        1    0.000    0.000    0.000    0.000 :0(print)
        1    0.000    0.000    0.000    0.000 :0(setprofile)
        1    0.000    0.000    0.000    0.000 <string>:1(<module>)
        1    0.000    0.000    0.000    0.000 Arithmetic.py:24(Arithmetic2)
       11    0.000    0.000    0.000    0.000 iostream.py:195(schedule)
       10    0.000    0.000    0.000    0.000 iostream.py:307(_is_master_process)
       10    0.000    0.000    0.000    0.000 iostream.py:320(_schedule_flush)
       10    0.000    0.000    0.000    0.000 iostream.py:382(write)
       11    0.000    0.000    0.000    0.000 iostream.py:93(_event_pipe)
        1    0.000    0.000    0.000    0.000 profile:0(Arithmetic2())
        0    0.000             0.000          profile:0(profiler)
        3    0.000    0.000    0.000    0.000 random.py:174(randrange)
        3    0.000    0.000    0.000    0.000 random.py:218(randint)
        3    0.000    0.000    0.000    0.000 random.py:224(_randbelow)
       11    0.000    0.000    0.000    0.000 socket.py:337(send)
       11    0.000    0.000    0.000    0.000 threading.py:1038(_wait_for_tstate_lock)
       11    0.000    0.000    0.000    0.000 threading.py:1080(is_alive)
       11    0.000    0.000    0.000    0.000 threading.py:507(is_set)


profile.run('Arithmetic3()')
问题是: 16 - 7 =          163 function calls in 0.000 seconds

   Ordered by: standard name

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
       11    0.000    0.000    0.000    0.000 :0(acquire)
       11    0.000    0.000    0.000    0.000 :0(append)
        3    0.000    0.000    0.000    0.000 :0(bit_length)
        1    0.000    0.000    0.000    0.000 :0(exec)
       10    0.000    0.000    0.000    0.000 :0(getpid)
        5    0.000    0.000    0.000    0.000 :0(getrandbits)
       10    0.000    0.000    0.000    0.000 :0(isinstance)
        1    0.000    0.000    0.000    0.000 :0(max)
        1    0.000    0.000    0.000    0.000 :0(min)
        1    0.000    0.000    0.000    0.000 :0(print)
        1    0.000    0.000    0.000    0.000 :0(setprofile)
        1    0.000    0.000    0.000    0.000 <string>:1(<module>)
        1    0.000    0.000    0.000    0.000 Arithmetic.py:41(Arithmetic3)
       11    0.000    0.000    0.000    0.000 iostream.py:195(schedule)
       10    0.000    0.000    0.000    0.000 iostream.py:307(_is_master_process)
       10    0.000    0.000    0.000    0.000 iostream.py:320(_schedule_flush)
       10    0.000    0.000    0.000    0.000 iostream.py:382(write)
       11    0.000    0.000    0.000    0.000 iostream.py:93(_event_pipe)
        1    0.000    0.000    0.000    0.000 profile:0(Arithmetic3())
        0    0.000             0.000          profile:0(profiler)
        3    0.000    0.000    0.000    0.000 random.py:174(randrange)
        3    0.000    0.000    0.000    0.000 random.py:218(randint)
        3    0.000    0.000    0.000    0.000 random.py:224(_randbelow)
       11    0.000    0.000    0.000    0.000 socket.py:337(send)
       11    0.000    0.000    0.000    0.000 threading.py:1038(_wait_for_tstate_lock)
       11    0.000    0.000    0.000    0.000 threading.py:1080(is_alive)
       11    0.000    0.000    0.000    0.000 threading.py:507(is_set)

profile.run('Arithmetic4()')
问题是: 13 - 4 =          162 function calls in 0.031 seconds

   Ordered by: standard name

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
       11    0.000    0.000    0.000    0.000 :0(acquire)
       11    0.031    0.003    0.031    0.003 :0(append)
        3    0.000    0.000    0.000    0.000 :0(bit_length)
        1    0.000    0.000    0.031    0.031 :0(exec)
       10    0.000    0.000    0.000    0.000 :0(getpid)
        4    0.000    0.000    0.000    0.000 :0(getrandbits)
       10    0.000    0.000    0.000    0.000 :0(isinstance)
        1    0.000    0.000    0.000    0.000 :0(max)
        1    0.000    0.000    0.000    0.000 :0(min)
        1    0.000    0.000    0.031    0.031 :0(print)
        1    0.000    0.000    0.000    0.000 :0(setprofile)
        1    0.000    0.000    0.031    0.031 <string>:1(<module>)
        1    0.000    0.000    0.031    0.031 Arithmetic.py:58(Arithmetic4)
       11    0.000    0.000    0.031    0.003 iostream.py:195(schedule)
       10    0.000    0.000    0.000    0.000 iostream.py:307(_is_master_process)
       10    0.000    0.000    0.000    0.000 iostream.py:320(_schedule_flush)
       10    0.000    0.000    0.031    0.003 iostream.py:382(write)
       11    0.000    0.000    0.000    0.000 iostream.py:93(_event_pipe)
        1    0.000    0.000    0.031    0.031 profile:0(Arithmetic4())
        0    0.000             0.000          profile:0(profiler)
        3    0.000    0.000    0.000    0.000 random.py:174(randrange)
        3    0.000    0.000    0.000    0.000 random.py:218(randint)
        3    0.000    0.000    0.000    0.000 random.py:224(_randbelow)
       11    0.000    0.000    0.000    0.000 socket.py:337(send)
       11    0.000    0.000    0.000    0.000 threading.py:1038(_wait_for_tstate_lock)
       11    0.000    0.000    0.000    0.000 threading.py:1080(is_alive)
       11    0.000    0.000    0.000    0.000 threading.py:507(is_set)

profile.run('Arithmetic5()')
问题是: 81 - 26 =          182 function calls in 0.016 seconds

   Ordered by: standard name

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
       11    0.000    0.000    0.000    0.000 :0(acquire)
       11    0.000    0.000    0.000    0.000 :0(append)
        7    0.000    0.000    0.000    0.000 :0(bit_length)
        1    0.000    0.000    0.016    0.016 :0(exec)
       10    0.000    0.000    0.000    0.000 :0(getpid)
        8    0.000    0.000    0.000    0.000 :0(getrandbits)
       10    0.000    0.000    0.000    0.000 :0(isinstance)
        1    0.000    0.000    0.000    0.000 :0(max)
        1    0.000    0.000    0.000    0.000 :0(min)
        1    0.000    0.000    0.000    0.000 :0(print)
        1    0.000    0.000    0.000    0.000 :0(setprofile)
        1    0.000    0.000    0.016    0.016 <string>:1(<module>)
        1    0.000    0.000    0.016    0.016 Arithmetic.py:75(Arithmetic5)
       11    0.000    0.000    0.000    0.000 iostream.py:195(schedule)
       10    0.000    0.000    0.000    0.000 iostream.py:307(_is_master_process)
       10    0.000    0.000    0.000    0.000 iostream.py:320(_schedule_flush)
       10    0.000    0.000    0.000    0.000 iostream.py:382(write)
       11    0.000    0.000    0.000    0.000 iostream.py:93(_event_pipe)
        1    0.000    0.000    0.016    0.016 profile:0(Arithmetic5())
        0    0.000             0.000          profile:0(profiler)
        7    0.000    0.000    0.016    0.002 random.py:174(randrange)
        7    0.000    0.000    0.016    0.002 random.py:218(randint)
        7    0.016    0.002    0.016    0.002 random.py:224(_randbelow)
       11    0.000    0.000    0.000    0.000 socket.py:337(send)
       11    0.000    0.000    0.000    0.000 threading.py:1038(_wait_for_tstate_lock)
       11    0.000    0.000    0.000    0.000 threading.py:1080(is_alive)
       11    0.000    0.000    0.000    0.000 threading.py:507(is_set)

profile.run('Arithmetic6()')
问题是: 196 + 36 =          184 function calls in 0.016 seconds

   Ordered by: standard name

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
       11    0.000    0.000    0.000    0.000 :0(acquire)
       11    0.000    0.000    0.000    0.000 :0(append)
        7    0.000    0.000    0.000    0.000 :0(bit_length)
        1    0.000    0.000    0.016    0.016 :0(exec)
       10    0.000    0.000    0.000    0.000 :0(getpid)
       12    0.000    0.000    0.000    0.000 :0(getrandbits)
       10    0.016    0.002    0.016    0.002 :0(isinstance)
        1    0.000    0.000    0.016    0.016 :0(print)
        1    0.000    0.000    0.000    0.000 :0(setprofile)
        1    0.000    0.000    0.016    0.016 <string>:1(<module>)
        1    0.000    0.000    0.016    0.016 Arithmetic.py:104(Arithmetic6)
       11    0.000    0.000    0.000    0.000 iostream.py:195(schedule)
       10    0.000    0.000    0.000    0.000 iostream.py:307(_is_master_process)
       10    0.000    0.000    0.000    0.000 iostream.py:320(_schedule_flush)
       10    0.000    0.000    0.016    0.002 iostream.py:382(write)
       11    0.000    0.000    0.000    0.000 iostream.py:93(_event_pipe)
        1    0.000    0.000    0.016    0.016 profile:0(Arithmetic6())
        0    0.000             0.000          profile:0(profiler)
        7    0.000    0.000    0.000    0.000 random.py:174(randrange)
        7    0.000    0.000    0.000    0.000 random.py:218(randint)
        7    0.000    0.000    0.000    0.000 random.py:224(_randbelow)
       11    0.000    0.000    0.000    0.000 socket.py:337(send)
       11    0.000    0.000    0.000    0.000 threading.py:1038(_wait_for_tstate_lock)
       11    0.000    0.000    0.000    0.000 threading.py:1080(is_alive)
       11    0.000    0.000    0.000    0.000 threading.py:507(is_set)
View Code

 

(七)时间记录

在实现完程序之后,用PSP表格记录下程序的各个模块上实际花费的时间

 

这是一套可以自动出题的小学四则运算系统,可以选择不同年级、不同次数进行练习。系统也会给出题目的正确答案。希望下次可以把可视化做的更好吧。

标签:11,10,iostream,py,CMMI,软件工程,实训,0.016,0.000
来源: https://www.cnblogs.com/eLiOFanG/p/13703093.html