题目
企业发放的奖金根据利润提成。利润(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,求应发放奖金总数?
程序分析 分区间计算即可。
profit=int(input('Show me the money: '))#输入当月利润,并转换为整数型
bonus=0 #设出奖金容量,并赋初值为0
thresholds=[100000,200000,400000,600000,1000000] #用列表存储数据
rates=[0.1,0.075,0.05,0.03,0.015,0.01]
for i in range(len(thresholds)): #len函数是返回容量中元素个数
if profit<=thresholds[i]:
bonus+=profit*rates[i]
profit=0
break
else:
bonus+=thresholds[i]*rates[i]
profit-=thresholds[i]
bonus+=profit*rates[-1] #最终奖金
print(bonus)