改进版四则运算
(1)Github地址:https://github.com/1281162169/newest-second-task
(2)PSP表格:
|
PSP2.1 |
Personal Software Process Stages |
预估耗时(分钟) |
实际耗时(分钟) |
|
Planning |
计划 |
60 |
30 |
|
· Estimate |
· 估计这个任务需要多少时间 |
60 |
30 |
|
Development |
开发 |
200 |
150 |
|
· Analysis |
· 需求分析 (包括学习新技术) |
60 |
60 |
|
· Design Spec |
· 生成设计文档 |
50 |
60 |
|
· Design Review |
· 设计复审 (和同事审核设计文档) |
20 |
20 |
|
· Coding Standard |
· 代码规范 (为目前的开发制定合适的规范) |
10 |
10 |
|
· Design |
· 具体设计 |
30 |
40 |
|
· Coding |
· 具体编码 |
200 |
200 |
|
· Code Review |
· 代码复审 |
40 |
30 |
|
· Test |
· 测试(自我测试,修改代码,提交修改) |
60 |
60 |
|
Reporting |
报告 |
100 |
100 |
|
· Test Report |
· 测试报告 |
60 |
60 |
|
· Size Measurement |
· 计算工作量 |
10 |
10 |
|
· Postmortem & Process Improvement Plan |
· 事后总结, 并提出过程改进计划 |
30 |
30 |
|
合计 |
|
990 |
890 |
(3)升级说明:这次升级增加了随机产生括号和把生成的四则运算题目保存在一个文档中,答案保存在另一个文档中。
(4)主要代码:
获得随机数字与符号:
def get_Arithmeticl(self):#获得随机数字与符号 symbol=[] numerical=[] syb=0 n=1 m=0 i=random.randint(1, 3) for x in range(i): sy=random.choice(['+','-','×','÷'])#随机选择[]中的一个 if sy=='+'or sy=='-': syb +=10**(i-x-1) else : syb += 2 * (10 ** (i - x - 1)) symbol.append(sy) if self.r < 10: n = int(10 / self.r) if n==1: while m <= i: numerical.append(Fraction(random.randint(1, self.r), random.randint(1, self.r))) m+=1 else: while m <= i: nu = Fraction(random.randint(1, self.r * n), random.randint(1, self.r * n)) if nu<=self.r: numerical.append(nu) m += 1 return symbol,syb,numerical,i
将假分数转化为真分数:
def get_Conversion(fraction):#假分数转化真分数 if fraction.numerator%fraction.denominator==0:#numerator分子 denominator分母 return '%d'%(fraction.numerator/fraction.denominator) elif fraction.numerator>fraction.denominator:#分子大于分母 a=int(fraction.numerator/fraction.denominator) b, c = fraction.numerator - a * fraction.denominator, fraction.denominator return '%d%s%d%s%d' % (a,'’',b,'/',c) else: b, c = fraction.numerator, fraction.denominator return '%d%s%d' % (b,'/',c)
(5)运行分析:
截图:

部分生成的四则运算:

部分答案:

浙公网安备 33010602011771号