|
发表于 2020-4-8 00:40:42
|
显示全部楼层
# 企业发放的奖金根据利润提成。利润(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,求应发放奖金总数?
print("第一种方法")
profit = float(input("输入利润(单位万元):"))
if profit < 0:
print('输入错误请重新输入')
profit = float(input("输入利润(单位万元):"))
bonus = 0.0
if profit <= 10:
bonus = profit*0.1
elif (profit > 10) and (profit <= 20):
bonus = (profit-10)*0.075 + 10*0.1
elif (profit > 20) and (profit <= 40):
bonus = (profit-20)*0.05 + 10*0.075 + 10*0.1
elif (profit > 40) and (profit <= 60):
bonus = (profit - 40) * 0.03 + 10 * 0.075 + 10 * 0.1 + 20*0.05
elif (profit > 60) and (profit <= 100):
bonus = (profit - 60) * 0.015 + 10 * 0.075 + 10 * 0.1 + 20 * 0.05 + 20*0.03
elif profit > 100:
bonus = (profit - 100) * 0.01 + 10 * 0.075 + 10 * 0.1 + 20 * 0.05 + 20*0.03 + 40*0.015
print("当月利润为", profit, "万元", "奖金为", bonus, "万元")
print("第二种方法")
# 输入利润
def inputProfit():
try:
profit = float(input("输入利润(单位万元):"))
return profit
except:
print("输入错误")
return inputProfit()
#计算奖金
profit = inputProfit()
profits = [0, 10, 20, 40, 60, 100]
#profits.reverse()
donuslike = [0.1, 0.075, 0.05, 0.03, 0.015, 0.01]
#donuslike.reverse()
def calculateBonus():
bonus2 = 0.0
if len(profits) != len(donuslike):
print("程序异常")
return
for i in range(len(profits)-1):
if (profit > profits[i]) and (profit >= profits[i+1]):
bonus2 = bonus2 + (profits[i+1]-profits[i])*donuslike[i]
elif (profit > profits[i]) and (profit < profits[i+1]):
bonus2 = bonus2 + (profit - profits[i])*donuslike[i]
# 单独比较最大值
if profit >= profits[len(profits)-1]:
bonus2 = bonus2 + (profit - profits[len(profits)-1])*donuslike[len(donuslike)-1]
return bonus2
print("当月利润为", profit, "万元", "奖金为", calculateBonus(), "万元")
|
|