python练习2
程序员文章站
2022-04-06 16:45:12
...
题目:企业发放的奖金根据利润提成。利润(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:
#! /usr/bin/env python
# -*- coding:utf-8 -*-
def func():
profits = float(input("净利润:"))
if profits <= 10:
profits = profits * 0.1
elif 10 < profits < 20:
profits = (profits - 10) * 0.075 + 10 * 0.1
elif 20 <= profits <= 40:
profits = (profits - 20) * 0.05 + 10 * 0.075 + 10 * 0.1
elif 40 < profits <= 60:
profits = (profits - 40) * 0.03 + 20 * 0.05 + 10 * 0.075 + 10 * 0.1
elif 60 < profits <= 100:
profits = (profits - 60) * 0.015 + 20 * 0.03 + 20 * 0.05 + 10 * 0.075 + 10 * 0.1
else:
profits = (profits - 100) * 0.01 + 40 * 0.015 + 20 * 0.03 + 20 * 0.05 + 10 * 0.075 + 10 * 0.1
print("应发放奖金总数:", profits * 10000)
if __name__ == "__main__":
func()
方法:
#! /usr/bin/env python
# -*- coding:utf-8 -*-
def func():
profits = float(input('净利润:'))
# 金额档次
step = [1000000, 600000, 400000, 200000, 100000, 0]
# 提成档次
commission = [0.01, 0.015, 0.03, 0.05, 0.075, 0.1]
# 奖金
bonus = 0
for i in range(len(step)):
if profits > step[i]:
# 每档分开计算,并做累加
bonus += (profits - step[i]) * commission[idx]
# 打印出每档的金额
print((profits - step[i]) * commission[idx])
# 把每档的金额赋值给利润
profits = step[i]
print("应发放奖金总数:",bonus)
if __name__ == "__main__":
func()