使用Python求根據提成計算的獎金
阿新 • • 發佈:2019-02-09
本程式在Python3的IDLE下執行通過,在Python2下出現的raw_input被取代了。題目如下:企業發放的獎金根據利潤提成。利潤(I)低於或等於10萬元時,獎金可提10%;
利潤高於10萬元,低於20萬元時,低於10萬元的部分按10%提成,高於10萬元的部分,可可提成7.5%;
20萬到40萬之間時,高於20萬元的部分,可提成5%;
40萬到60萬之間時高於40萬元的部分,可提成3%;
60萬到100萬之間時,高於60萬元的部分,可提成1.5%,
高於100萬元時,超過100萬元的部分按1%提成,
從鍵盤輸入當月利潤I,求應發放獎金總數?
利潤高於10萬元,低於20萬元時,低於10萬元的部分按10%提成,高於10萬元的部分,可可提成7.5%;
20萬到40萬之間時,高於20萬元的部分,可提成5%;
40萬到60萬之間時高於40萬元的部分,可提成3%;
60萬到100萬之間時,高於60萬元的部分,可提成1.5%,
高於100萬元時,超過100萬元的部分按1%提成,
從鍵盤輸入當月利潤I,求應發放獎金總數?
profit = int(input('Enter the profit: ')) arr = [1000000,6000000,400000,200000,100000,0]#利潤臨界點。 rat = [0.01,0.015,0.03,0.05,0.075,0.1]#提成臨界點。 reward = 0.0 for idx in range(6): if profit > arr[idx]: tmp = (profit - arr[idx])*rat[idx] reward += tmp print(tmp) profit = arr[idx]#設定為零界點。 print('應該發放的獎金總額是%f萬元'%reward)#注意格式是%f。