个人PSP(四则运算)升级
Github项目地址:https://github.com/zb37/-/blob/master/README.md
1.题目要求:
A. 可以自动生成小学四则运算题目
B. 除了整数外,还要支持真分数的四则运算
C.个人PSP (四则运算) 升级作业:
要求:对你们上一次四则运算作业进行一次升级,必须有P S P 2.1标准步骤。
升级方式: (可选, 最少选一个升级方向) :
(1) 功能升级, (2) 界升级,(3) 性能升级, (4) 胚同语写升级
2.思路:
a.随机选择四则运算加减乘除
b.随机采用两个随机数,分整数和真分数两部分
c.由于不能出现负数,所以在对两个随机数进行减法运算的时候,需要进行比较大小,而除法在运算中,除数不能取0。
d.判断结果对错,给出正确答案
e.升级方向是建题库不用一道一道出题这么麻烦
3.工具清单:
1)编程语言:python
2) 效能分析工具:profile
3)源代码管理平台:Gitbee
4.PSP表格
附:PSP 2.1表格
| PSP2.1 | Personal Software Process Stages | 预估耗时(分钟) | 实际耗时(分钟) |
|---|---|---|---|
| Planning | 计划 | 30 | 30 |
| · Estimate | · 估计这个任务需要多少时间 | 1440 | 720 |
| Development | 开发 | 120 | 360 |
| · Analysis | · 需求分析 (包括学习新技术) | 10 | 10 |
| · Design Spec | · 生成设计文档 | ||
| · Design Review | · 设计复审 (和同事审核设计文档) | ||
| · Coding Standard | · 代码规范 (为目前的开发制定合适的规范) | ||
| · Design | · 具体设计 | ||
| · Coding | · 具体编码 | ||
| · Code Review | · 代码复审 | 5 | 5 |
| · Test | · 测试(自我测试,修改代码,提交修改) | 60 | 30 |
| Reporting | 报告 | 30 | 20 |
| · Test Report | · 测试报告 | 30 | 20 |
| · Size Measurement | · 计算工作量 | 5 | 5 |
| · Postmortem & Process Improvement Plan | · 事后总结, 并提出过程改进计划 | 10 | 10 |
| 合计 | 1740 | 1230 |
1 import random
2 from fractions import Fraction
3 def zs():
4
5 fz= ['+', '-', '×', '÷']#随机选择运算法则
6
7 f= random.randint(0, 3)
8
9 n1 = random.randint(0,99)
10
11 n2 = random.randint(0,99)
12
13 result = 0
14
15 if f== 0:#加法
16
17 result = n1 + n2
18
19 elif f == 1:#减法,要先比较大小,防止输出负数
20
21 n1, n2 = max(n1, n2), min(n1, n2)
22
23 result = n1 - n2
24
25 elif f== 2:#乘法
26
27 result = n1 * n2
28
29 elif f == 3:#除法
30 n2 = random.randint(1,99)
31
32 result = n1 / n2
33
34 print(n1, fz[f], n2, '= ', end='')
35
36 return result
37 def xs():
38
39 fz= ['+', '-', '×', '÷']
40
41 f= random.randint(0, 3)
42
43 x1 = random.randint(0,20)#生成2个真分数,约分通分较复杂所以数值设的较小
44 if x1==0:
45 x2 = random.randint(1,20)
46 else:
47 x2 = random.randint(x1,20)
48 x3 = random.randint(0,20)
49 if x3==0:
50 x4 = random.randint(1,20)
51 else:
52 x4 = random.randint(x3,20)
53 n1 = Fraction(x1,x2)
54 n2 = Fraction(x3,x4)
55 result = 0
56
57 if f== 0:#加法
58
59 result = n1 + n2
60
61 elif f == 1:#减法,要先比较大小,防止输出负数
62
63 n1, n2 = max(n1, n2), min(n1, n2)
64
65 result = n1 - n2
66
67 elif f== 2:#乘法
68
69 result = n1 * n2
70
71 elif f == 3:#除法
72
73 result = n1 / n2
74
75 print(n1, fz[f], n2, '= ', end='')
76
77 return result
78 def chuti():
79 x= random.randint(1,2)
80 if x==1:
81 result=str(zs())
82 elif x==2:
83 result=str(xs())
84 return result
85
86 #制作题库
87
88 def test():
89 print('输入所需要的题目数量')
90
91 n=int(input())
92
93 result =[]
94
95 m=0
96
97 while m<=(n-1):
98
99 print(m+1,end='、')
100 result .append(chuti())
101 print(' ')
102 m=m+1
103
104 m=0
105
106 print('对应的答案:')
107
108 while m<=(n-1):
109
110 print(m+1,'、',result [m])
111
112 m=m+1
113
114
115
116 print('选择想要的模式')
117
118 print('1、进行单道四则运算')
119
120 print('2、制作题库')
121
122 n=int(input())
123
124 #当输入1时,进行单道四则运算
125
126 if n==1:
127
128 while True:
129 x= random.randint(1,2)#随机选择整数或者分数的题型
130 if x==1:
131 result=str(zs())
132 y=input()
133 if y==result:
134 print('答对了')
135 else:
136 print('答错了,正确答案是:',result)
137 elif x==2:
138 result=str(xs())
139 y=input()
140 if y==result:
141 print('答对了')
142 else:
143 print('答错了,正确答案是:',result)
144 #当输入2时,进行制作题库
145
146 if n==2:
147
148 test()
149
6.运行测试

7.性能分析




浙公网安备 33010602011771号