练习二:数轴、长整型 企业发放的奖金根据利润提成

题目:
企业发放的奖金根据利润提成。
# 利润(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,求应发放奖金总数?
方法一;
profits = int(input('请输入当月利润(万元):'))
reward = 0
if profits <= 10:
    reward = profits*0.1
# if 10<profits <= 20:#用if和用elif效果相同
elif 10<profits <= 20:
    reward = 10*0.1 + (profits-10)*0.075
# if 20<profits <= 40:
elif 20<profits <= 40:
    reward = 10*0.1 + 10*0.075 + (profits-20)*0.05
# if 40<profits <= 60:
elif 40<profits <= 60:
    reward = 10*0.1 + 10*0.075 + 20*0.05 +(profits-40)*0.03
# if 60<profits <= 100:
elif 60<profits <= 100:
    reward = 10*0.1 + 10*0.075 + 20*0.05 + 40*0.03 +(profits-60)*0.015
# if profits > 100:
elif profits > 100:
    reward = 10*0.1 + 10*0.075 + 20*0.05 + 40*0.03 +60*0.015 + (profits-100)*0.01
print(reward)

方法二:

profits = int(input('请输入当月利润(万元):'))
rat = [0.01,0.015,0.03,0.05,0.075,0.1]
arr = [100,60,40,20,10,0]
reward = 0
for i in range(6):
    if profits > arr[i]:
        reward += (profits-arr[i])*rat[i] #利润大于arr[i],则收入为大于arr[i]部分+小于arr[i]
        # print((profits-arr[i])*rat[i])
        profits = arr[i]  #循环大于arr[i]计算完毕后,将arr[i]赋值给利润,再次计算
print(reward)

 

posted @ 2018-10-25 21:45  阳光宝贝-沐沐  阅读(197)  评论(0编辑  收藏  举报