题目:企业发放的奖金根据利润提成。利润(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,求应发放奖金总数
这题我在编程时,借助画图软件把题目给定的区间范围及所对应的值理一理,方便我后续进行计算。然后由图可知,当我用键盘输入某个值时,包括该值所在的区间以及之前的区间对应的百分比都得参与计算。具体代码如下:

x1 = 100000 * 0.1
x2 = (200000 - 100000) * 0.075
x3 = (400000 - 200000) * 0.05
x4 = (600000 - 400000) * 0.03
x5 = (1000000 - 600000) * 0.015
bonus = 0 # 初始奖金
profit = float(input("Please input the profit in this mouth:")) # 利润
if profit <= 100000:
bonus = profit * 0.1
elif profit > 100000 and profit <= 200000:
bonus = (profit - 100000) * 0.075 + x1
elif profit > 200000 and profit <= 400000:
bonus = (profit - 200000) * 0.05 + x1 + x2
elif profit > 400000 and profit <= 600000:
bonus = (profit - 400000) * 0.03 + x1 + x2 + x3
elif profit > 600000 and profit <= 1000000:
bonus = (profit - 600000) * 0.015 + x1 + x2 + x3 + x4
else:
bonus = (profit - 1000000) * 0.01 + x1 + x2 + x3 + x4 + x5
print(bonus)
2045






