1.Github项目地址:
https://github.com/hi00785/-1/blob/master/%E5%9B%9B%E5%88%99%E8%BF%90%E7%AE%97.py
2.程序的各个模块的开发上耗费的时间:
PSP2.1 | Personal Software Process Stages | 预估耗时(分钟) | 实际耗时(分钟) |
Planning | 计划 | 5 | 5 |
· Estimate | · 估计这个任务需要多少时间 | ||
Development | 开发 | 305 | 305 |
· Analysis | · 需求分析 (包括学习新技术) | 20 | 20 |
· Design Spec | · 生成设计文档 | 40 | 40 |
· Design Review | · 设计复审 (和同事审核设计文档) | ||
· Coding Standard | · 代码规范 (为目前的开发制定合适的规范) | ||
· Design | · 具体设计 | 30 | 30 |
· Coding | · 具体编码 | 100 | 100 |
· Code Review | · 代码复审 | 50 | 50 |
· Test | · 测试(自我测试,修改代码,提交修改) | ||
Reporting | 报告 | 90 | 90 |
· Test Report | · 测试报告+博客 | 60 | 60 |
· Size Measurement | · 计算工作量 | ||
· Postmortem & Process Improvement Plan | · 事后总结, 并提出过程改进计划 | ||
合计 | 400 |
3.解题思路:
(1)根据小学生的加减乘除四则运算的知识,需要分为整数运算和分数运算
(2)处理分数是,要约分到不可约,引入fraction函数
(3)让学生自行选择是运算整数或是分数,采用随机函数生成4个数,组合成两个分数,进行加减乘除运算
(4)运用time库中的perf_count()进行计时,进行效能分析,优化代码
4.设计实现过程:
会用到随机函数random.randint,分数处理函数Fraction,计时函数perf_count()
5.代码说明:
rom fractions import *
import numpy
import time
def size():
start=time.perf_counter()
print("您算分数,还是整数?")
a=input()
if a=="分数":
temp = input("是加减乘除哪一个?请输入运算符号:")
x = numpy.random.randint(1,50)
y = numpy.random.randint(1,50)
b = numpy.random.randint(1,50)
c = numpy.random.randint(1,50)
if temp == "+":
print("答案为:%s+%s=%s"%(Fraction(x,y),Fraction(b,c),Fraction(x, y) + Fraction(b, c)))
elif temp == "-":
print("答案为:%s-%s=%s" % (Fraction(x, y), Fraction(b, c), Fraction(x, y) - Fraction(b, c)))
elif temp == "*":
print("答案为:%s*%s=%s" % (Fraction(x, y), Fraction(b, c), Fraction(x, y) * Fraction(b, c)))
elif temp == "/":
print("答案为:%s/%s=%s" % (Fraction(x, y), Fraction(b, c), Fraction(x, y) / Fraction(b, c)))
elif a=="整数":
x=numpy.random.randint(1,50)
y=numpy.random.randint(1,50)
temp = input("加减乘除?")
if temp == "+":
print("答案为:{:d}+{:d}={:d}" .format(x, y, x+y))
elif temp == "-":
print("答案为:{:d}-{:d}={:d}" .format(x, y, x-y))
elif temp == "*":
print("答案为:{:d}*{:d}={:d}".format(x, y, x*y))
elif temp == "/":
print("答案为:{:d}/{:d}={:.2f}" .format(x, y, x/y))
else:
print("您输入的数据有误")
end=time.perf_counter()
print("程序运行时间:{:.3f}".format(end-start))
size()
6.测试运行:

7.效能分析:
由于并不太会效能分析,仍在努力学习中,这部分在改进