应发奖金计算
简述:企业发放的奖金根据利润提成。利润(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第一种实现代码:
1 #奖金计算 2 def reward(profit): 3 reward = 0.0 4 if profit<=10: 5 return profit*0.1 6 elif profit<=20 and profit>10: 7 return (profit-10)*0.075+1 8 elif profit<=40 and profit>20: 9 return (profit-20)*0.05+10*0.1+10*0.075 10 elif profit<=60 and profit>40: 11 return (profit-40)*0.03+20*0.05+10*0.075+10*0.1 12 elif profit<=100 and profit>60: 13 return (profit-60)*0.015+20*0.03+20*0.05+10*0.075+10*0.1 14 elif profit>100: 15 return (profit-100)*0.01+40*0.015+20*0.03+20*0.05+10*0.075+10*0.1 16 17 if __name__ == "__main__": 18 profit = float(input("请输入当月利润(万): ")) 19 print( reward(profit)*10000)
输出结果:
1 请输入当月利润(万): 14 2 13000.0
02第二种实现代码:
1 #奖金计算 2 def reward(profit): 3 arr = [100,60,40,20,10,0] 4 rat = [0.01,0.015,0.03,0.15,0.075,0.1] 5 reward = 0 6 for idx in range(0,6): 7 if profit > arr[idx]: 8 reward += ((profit-arr[idx]) * rat[idx]) 9 #print((profit - arr[idx]) * rat[idx]) 10 profit = arr[idx] 11 print(reward*10000) 12 if __name__ == "__main__": 13 profit = float(input("请输入当月利润(万): ")) 14 reward(profit)
输出结果:
1 请输入当月利润(万): 14 2 13000.0