應發獎金計算
簡述:企業發放的獎金根據利潤提成。利潤(profit)低於或等於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%提成.
提問:從鍵盤輸入當月利潤profit,求應發放獎金總數?
01第一種實現**:
輸出結果:#獎金計算
defreward
(profit)
: reward =
0.0if profit<=10:
return profit*
0.1elif profit<=
20and profit>10:
return
(profit-10)
*0.075+1
elif profit<=
40and profit>20:
return
(profit-20)
*0.05+10
*0.1+10
*0.075
elif profit<=
60and profit>40:
return
(profit-40)
*0.03+20
*0.05+10
*0.075+10
*0.1
elif profit<=
100and profit>60:
return
(profit-60)
*0.015+20
*0.03+20
*0.05+10
*0.075+10
*0.1
elif profit>
100:
return
(profit-
100)
*0.01+40
*0.015+20
*0.03+20
*0.05+10
*0.075+10
*0.1
if __name__ ==
"__main__"
: profit =
float
(input
("請輸入當月利潤(萬): "))
( reward(profit)
*10000
)
02第二種實現**:請輸入當月利潤(萬): 14
13000.0
輸出結果:'''
'''#獎金計算
defreward
(profit)
: arr =
[100,60
,40,20
,10,0
] rat =
[0.01
,0.015
,0.03
,0.15
,0.075
,0.1
] reward =
0for idx in
range(0
,6):
if profit > arr[idx]
: reward +=
((profit-arr[idx]
)* rat[idx]
)#print((profit - arr[idx]) * rat[idx])
profit = arr[idx]
(reward*
10000
)if __name__ ==
"__main__"
: profit =
float
(input
("請輸入當月利潤(萬): "))
reward(profit)
請輸入當月利潤(萬): 14
13000.0
python實現10進製轉換2進製(兩種方法)
兩種方式 1 定義函式實現 整數除二,餘數進棧 2 用python內建函式bin 實現 一 用棧來實現10進製轉2進製 用函式實現十進位制與二進位制的轉換 deftentotwo number 定義棧 s binstring while number 0 餘數進棧 rem number 2 numb...
Redhat nis client兩種接入方式
redhat nis client兩種接入方式 在redhat上nis client有兩種方式接入nis伺服器 etc nsswitch.conf和system config authentication 通過 etc nsswitch.conf的方式使用者只能通過yppasswd進行修改密碼且無法...
python threading 兩種建立方式
作用 建立在thread模組之上,可以更容易地管理多個執行執行緒。通過使用執行緒,程式可以在同乙個程序空間併發地執行多個操作。threading模組建立在thread的底層特性基礎上,可以更容易地完成執行緒處理。1 呼叫函式 要使用thread,最簡單的方法就是用乙個目標函式例項化乙個thread物...