四则运算升级

1.题目要求:

   要求:四则运算作业进行一次升级,必须有P S P 2.1标准步骤。
   升级方式: (可选, 最少选一个升级方向) :
   (1) 功能升级, (2) 界升级,(3) 性能升级, (4) 用不同语言写升级

 2.PSP表格:

    预计耗时(分钟) 实际耗时(分钟)
Planning 计划 30 30
Estimate 估计这个任务需要多少时间 5 5
Development 开发 90 90
Analysis 需求分析 10 10
Design Spec 生成设计文档 0 0
Design Review 设计复审(和同事审核设计文档) 0 0
Coding Standerd 代码规范(为目前的开发制定合适的规范) 5 5
Design 具体设计 20 30
Coding 具体编码 90 90
Code Review 代码复审 10 10
Text 测试(自测,修改代码,提交修改) 20 20
Reporting 报告 10 10
Text Report 测试报告 10 10
Size Measurement 计算工作量 5 5
Postmortem & Process Improvement Plan 事后总结,并提出过程改进计划 20 20
Sum 合计 325 335

3.代码说明

  1 from tkinter import *
  2 import random
  3 from fractions import Fraction
  4 
  5 root = Tk()
  6 root.title("四则运算")
  7 root.geometry("605x500+300+100")
  8 
  9 label = Label(root,text="现有如下5种题型:1)整数加减 2)小数加减3)分数加减 4)整数乘除 5)分数乘除",font=("微软雅黑",12),fg='red')
 10 label.place(x=0,y=10)
 11 label2 = Label(root,text="请选择下列想要的题型:",font=("微软雅黑",12),fg='red')
 12 label2.place(x=220,y=180)
 13 label2 = Label(root,text="难度等级:初级(0-50)、中级(0-100)、高级(0-200)",font=("微软雅黑",12),fg='red')
 14 label2.place(x=0,y=40)
 15 label4 = Label(root,text="请输入想要的难度:",font=("微软雅黑",12),fg='red')
 16 label4.place(x=120,y=80)
 17 label4 = Label(root,text="请输入想要的题数:",font=("微软雅黑",12),fg='red')
 18 label4.place(x=320,y=80)
 19 
 20 entry1 = Entry()
 21 entry1.place(x=120,y=115)
 22 entry2 = Entry()
 23 entry2.place(x=320,y=115)
 24 level=''
 25 homeworkCount=''
 26 
 27 def easy():
 28     level=entry1.get()
 29     homeworkCount=entry2.get()
 30     print(level)
 31     print(homeworkCount)
 32     button=Button(root,text="确认",command=easy,width=15,height=1)
 33     button.pack()
 34     button.place(x=230,y=145)
 35 
 36 def one():
 37     count=0
 38     level=entry1.get()
 39     homeworkCount=entry2.get()
 40     if level=="初级":
 41         level=50
 42     elif level=="中级":
 43         level=100
 44     else:
 45         level=200
 46     while count<int(homeworkCount):
 47         count=count+1
 48         print("第"+str(count)+"道题目");
 49         intAddSub(level)
 50         print("\n")
 51     print('end!!!')
 52         
 53 def two():
 54     count=0
 55     level=entry1.get()
 56     homeworkCount=entry2.get()
 57     if level=="初级":
 58         level=50
 59     elif level=="中级":
 60         level=100
 61     else:
 62         level=200
 63     while count<int(homeworkCount):
 64         count=count+1
 65         print("第"+str(count)+"道题目")
 66         decAddSub(level)
 67         print("\n")
 68     print('end!!!')
 69         
 70 def three():
 71     count=0
 72     level=entry1.get()
 73     homeworkCount=entry2.get()
 74     if level=="初级":
 75         level=50
 76     elif level=="中级":
 77         level=100
 78     else:
 79         level=200
 80     while count<int(homeworkCount):
 81         count=count+1
 82         print("第"+str(count)+"道题目")
 83         fraAddSub(level)
 84         print("\n")
 85     print('end!!!')
 86 
 87 def four():
 88     count=0
 89     level=entry1.get()
 90     homeworkCount=entry2.get()
 91     if level=="初级":
 92         level=50
 93     elif level=="中级":
 94         level=100
 95     else:
 96         level=200
 97     while count<int(homeworkCount):
 98         count=count+1
 99         print("第"+str(count)+"道题目")
100         intMulDiv(level)
101         print("\n")
102     print('end!!!')
103 
104 def five():
105     count=0
106     level=entry1.get()
107     homeworkCount=entry2.get()
108     if level=="初级":
109         level=50
110     elif level=="中级":
111         level=100
112     else:
113         level=200
114     while count<int(homeworkCount):
115         count=count+1
116         print("第"+str(count)+"道题目")
117         fraMulDiv(level)
118         print("\n")
119     print('end!!!')
120 
121 def closewindows():
122     root.destroy()
123 
124 def intAddSub(level):
125     typeCal=random.randint(0,1);     #选择加减运算符
126     num1=random.randint(0,level)    #生成随机整数
127     num2=random.randint(0,level)
128     if typeCal==0:
129         print(str(num1)+"+"+str(num2)+"=?")
130         ans1=input("您的答案是:")
131         print("正确答案是:"+str(num1+num2))
132     else:
133         if num1<num2:
134             t=num1
135             num1=num2
136             num2=t
137         print(str(num1)+"-"+str(num2)+"=?")
138         ans2=input("您的答案是:")
139         print("正确答案是:"+str(num1-num2))
140 
141 def decAddSub(level):
142     typeCal=random.randint(0,1)      #选择加减运算符
143     num1=random.uniform(0,level)   #生成随机整数
144     num1=round(num1,2)
145     num2=random.uniform(0,level)
146     num2=round(num2,2)
147     if typeCal==0:
148         print(str(num1)+"+"+str(num2)+"=?")
149         ans1=input("您的答案是:")
150         print("正确答案是:{:.2f}".format(num1+num2))
151     else:
152         if num1<num2:
153             t=num1
154             num1=num2
155             num2=t
156         print(str(num1)+"-"+str(num2)+"=?")
157         ans2=input("您的答案是:")
158         print("正确答案是:{:.2f}".format(num1-num2))
159 
160 def fraAddSub(level):
161     typeCal=random.randint(0,1)     #选择加减运算符
162     molecule1=random.randint(0,level)    #生成随机整数
163     denominator1=random.randint(1,level)
164     num1=Fraction(molecule1,denominator1)
165     molecule2=random.randint(0,level)
166     denominator2=random.randint(1,level)
167     num2=Fraction(molecule2,denominator2)
168     if typeCal==0:
169         print(str(num1)+"+"+str(num2)+"=?")
170         ans1=input("您的答案是:")
171         print("正确答案是:"+str(num1+num2))
172     else:
173         if num1<num2:
174             t=num1
175             num1=num2
176             num2=t
177         print(str(num1)+"-"+str(num2)+"=?")
178         ans2=input("您的答案是:")
179         print("正确答案是:"+str(num1-num2))
180 
181 def intMulDiv(level):
182     typeCal=random.randint(0,1)     #选择加减运算符
183     num1=random.randint(0,level)   #生成随机整数
184     num2=random.randint(0,level)
185     if typeCal==0:
186         print(str(num1)+"×"+str(num2)+"=?")
187         ans1=input("您的答案是:")
188         print("正确答案是:"+str(num1*num2))
189     else:
190         print(str(num1)+"÷"+str(num2)+"=?")
191         ans2=input("您的答案是:")
192         print("正确答案是:{:.2f}".format(num1/num2))
193 
194 def fraMulDiv(level):
195     typeCal=random.randint(0,1)     #选择加减运算符
196     molecule1=random.randint(0,level)    #生成随机整数
197     denominator1=random.randint(1,level)
198     num1=Fraction(molecule1,denominator1)
199     molecule2=random.randint(0,level);
200     denominator2=random.randint(1,level)
201     num2=Fraction(molecule2,denominator2)
202     if typeCal==0:
203         print(str(num1)+"×"+str(num2)+"=?")
204         ans1=input("您的答案是:");
205         print("正确答案是:"+str(num1*num2))
206     else:
207         print(str(num1)+"÷"+str(num2)+"=?")
208         ans2=input("您的答案是:");
209         print("正确答案是:"+str(num1/num2))
210 
211 btn1 = Button(root,text="整数加减",width=30,height=2,bg="pink",fg="blue",command=one)
212 btn1.pack()
213 btn1.place(x=50,y=220)
214 
215 btn2 = Button(root,text="小数加减",width=30,height=2,bg="pink",fg="blue",command=two)
216 btn2.pack()
217 btn2.place(x=50,y=300)
218 
219 btn3 = Button(root,text="分数加减",width=30,height=2,bg="pink",fg="blue",command=three)
220 btn3.pack()
221 btn3.place(x=50,y=380)
222 
223 btn4 = Button(root,text="整数乘除",width=30,height=2,bg="pink",fg="blue",command=four)
224 btn4.pack()
225 btn4.place(x=320,y=220)
226 
227 btn5 = Button(root,text="分数乘除",width=30,height=2,bg="pink",fg="blue",command=five)
228 btn5.pack()
229 btn5.place(x=320,y=300)
230 
231 btn6 = Button(root,text="退出",width=30,height=2,bg="pink",fg="blue",command=closewindows)
232 btn6.pack()
233 btn6.place(x=320,y=380)
234 
235 root.mainloop()

4.结果展示

 

posted @ 2021-09-19 21:03  youto有病  阅读(44)  评论(0编辑  收藏  举报