Python3经典100道练习题002

题目:企业发放的奖金根据利润提成。利润(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,求应发放奖金总数?

 1 x=input('请输入获得的利润:')
 2 x=int(x)
 3 if x<=100000:
 4     y=x*0.1
 5 elif x<=20000:
 6     y=10000+(x-100000)*0.075
 7 elif x<=40000:
 8     y=10000+7500+(x-200000)*0.05
 9 elif x<=60000:
10     y=10000+7500+10000+(x-400000)*0.03
11 elif x<=1000000:
12     y=10000+7500+10000+6000+(x-600000)*0.015
13 elif x>1000000:
14     y=10000+7500+10000+6000+6000+(x-1000000)*0.01
15                               
16                                 
17 print('提成为:',y) 

【网络高手的方法】

 1 def  get_reward(I):
 2     rewards = 0
 3     if I <= 10:
 4         rewards = I * 0.1
 5 
 6     elif (I > 10) and (I <= 20):
 7         rewards = (I - 10) * 0.075 + get_reward(10)
 8 
 9     elif (I > 20) and (I <= 40):
10         rewards = (I - 20) * 0.05 + get_reward(20)
11 
12     elif (I > 40) and (I <= 60):
13         rewards = (I - 40) * 0.03 + get_reward(40)
14 
15     elif (I > 60) and (I <= 100):
16         rewards = (I - 60) * 0.015 + get_reward(60)
17 
18     else:
19         rewards = get_reward(100) + (I - 100) * 0.01
20 
21     return rewards
22 
23 if __name__ == '__main__':
24     i = 120000
25     print("净利润:", i)
26     print("发放的奖金为:", get_reward(i / 10000) * 10000)
原文地址:https://www.cnblogs.com/mathpro/p/7943995.html