四則運算

Github地址:https://github.com/sjzsjzsjz/jisuangit

PSP表格:github

 

 

預測時間(分鐘)app

nningdom

計劃函數

2工具

Estimate性能

估計這個任務須要多少時間學習

120測試

Development編碼

開發

10

Analysis

需求分析

10

Design Spec

生成設計文檔

3

Design Review

設計複審(和同事審覈設計文檔)

2

Coding Standerd

代碼規範(爲目前的開發制定合適的規範)

1

Design

具體設計

5

Coding

具體編碼

60

Code Review

代碼複審

10

Text

測試(自測,修改代碼,提交修改)

5

Reporting

報告

10

Text Report

測試報告

10

Size Measurement

計算工做量

5

Postmortem & Process Improvement Plan

過後總結,並提出過程改進計劃

10

 

解題思路描述:

(1) 思考如何隨機生成四則運算表達式

(2) 查閱相關博客,瞭解效能分析所用工具

(3) 學習所用到的類庫,如random庫

 

設計實現過程:

這個四則運算表達式由三個函數實現,分別爲create1()、create2()、calcul(),前兩個函數負責生成表達式,最後一個表達式負責計算結果。

 

代碼說明:

def create1(t):
    s1=random.randint(1,10)
    s2=random.randint(1,10)
    s3=random.choice(['+','-','*','/'])
    calcul(s1,s2,s3,t)

def create2(t):
    s1=random.randint(1,10)
    s2=random.randint(s1,11)
    s3=random.randint(1,10)
    s4=random.randint(s3,11)
    s5=random.choice(['+','-'])
    sr="第"+str(t)+"題:"+str(s1)+'÷'+str(s2)+s5+str(s3)+'÷'+str(s4)+'='
    l1.append(sr)
    if s5=='+':
        l2.append(s1/s2+s3/s4)
    else:
        if s1/s2-s3/s4>0:
            l2.append(s1/s2-s3/s4)
        else:
            sr="第"+str(t)+"題:"+str(s3)+'÷'+str(s4)+s5+str(s1)+'÷'+str(s2)+'='
            l2.append(s3/s4-s1/s2)
def calcul(s1,s2,s3,t):
    sr="第"+str(t)+"題:"+str(s1)+s3+str(s2)+'='
    if s3=='+':
        l2.append(s1+s2)
    elif s3=='-':
        if s1>=s2:
            l2.append(s1-s2)
        else:
            sr="第"+str(t)+"題:"+str(s2)+s3+str(s1)+'='
            l2.append(s2-s1)
    elif s3=='*':
        sr="第"+str(t)+"題:"+str(s1)+'x'+str(s2)+'='
        l2.append(s1*s2)
    elif s3=='/':
        sr="第"+str(t)+"題:"+str(s1)+'÷'+str(s2)+'='
        l2.append(s1/s2)
    l1.append(sr)

 

測試運行:

 

性能分析:

這個程序經過使用cProfile和time模塊來測試程序的性能

 

 

PSP表格:

 

 

實際時間(分鐘)

nning

計劃

10

Estimate

估計這個任務須要多少時間

180

Development

開發

10

Analysis

需求分析

10

Design Spec

生成設計文檔

3

Design Review

設計複審(和同事審覈設計文檔)

2

Coding Standerd

代碼規範(爲目前的開發制定合適的規範)

1

Design

具體設計

5

Coding

具體編碼

90

Code Review

代碼複審

20

Text

測試(自測,修改代碼,提交修改)

5

Reporting

報告

30

Text Report

測試報告

10

Size Measurement

計算工做量

5

Postmortem & Process Improvement Plan

過後總結,並提出過程改進計劃

10

相關文章
相關標籤/搜索