题目
企业发放的奖金根据利润提成。利润(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,求应发放奖金总数?
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
-------------------------------------------------
File Name: python练习100——【002】个税计算
Description : python practice
Author : zhangzx
date: 2020-12-02
-------------------------------------------------
Change Activity:
2020-02-19
-------------------------------------------------
"""
# 解法一:C++ 思维
profit_0 = int(input('Show me your profit_0,and I will comulate your bouns_0: '))
if profit_0 > 1000000:
bouns_0 = (profit_0 - 1000000)* 0.01 + (1000000 - 600000)* 0.015 + (600000 - 400000)* 0.03 + \
(400000- 200000)* 0.05 + (200000 - 100000)* 0.075 + 100000* 0.1
elif profit_0 > 600000:
bouns_0 = (profit_0 - 600000)* 0.015 + (600000 - 400000)* 0.03 + \
(400000- 200000)* 0.05 + (200000 - 100000)* 0.075 + 100000* 0.1
elif profit_0 > 400000:
bouns_0 = (profit_0 - 400000)* 0.03 + (400000- 200000)* 0.05 + (200000 - 100000)* 0.075 + 100000* 0.1
elif profit_0 > 200000:
bouns_0 = (profit_0 - 200000)* 0.05 + (200000 - 100000)* 0.075 + 100000* 0.1
elif profit_0 > 100000:
bouns_0 = (profit_0 - 100000)* 0.075 + 100000* 0.1
else:
bouns_0 = profit_0 * 0.1
print ("your bouns_0 is : " + str(bouns_0)+ '\n')
# 解法二:Python思维
profit_1 = int(input('Show me your profit_1,and I will comulate your bouns_1: '))
bonus_1 = 0
thresholds=[100000,100000,200000,200000,400000] # 各阶梯价格之差(10-0=10, 20-10=10, 40-20=20, 60-40=20, 100-60=40)
rates=[0.1,0.075,0.05,0.03,0.015,0.01]
for i in range(len(thresholds)):
if profit_1 <= thresholds[i]:
#print(profit_1, thresholds[i])
bonus_1 += profit_1 * rates[i]
#print(str(bonus_1) + "\n")
profit_1 = 0
break
else:
bonus_1 += thresholds[i]*rates[i]
#print(thresholds[i], rates[i])
profit_1 -= thresholds[i]
#print(str(profit_1) + "\n")
#print(profit_1, rates[-1])
bonus_1+= profit_1 * rates[-1]
print("your bouns_1 is : " + str(bonus_1) + '\n')
#解法三:结合1和2
profit_2 = int(input('Show me your profit_2,and I will comulate your bouns_2: '))
arr = [1000000, 600000, 400000, 200000, 100000, 0]
rat = [0.01, 0.015, 0.03, 0.05, 0.075, 0.1]
for j in range(len(arr)):
if profit_2 >= arr[j]:
bonus_2 = rat[j] * (profit_2 - arr[j])
for k in range(j+1,6):
bonus_2 = bonus_2 + (arr[k-1] - arr[k]) * rat[k]
break
print('your bouns_2 is :' + str(bonus_2))
'''
下文是验证方法三的:
-----------------------------
profit_2 = int(input('Show me your profit_2,and I will comulate your bouns_2: '))
arr = [100, 60, 40, 20, 10, 0]
rat = [0.01, 0.015, 0.03, 0.05, 0.075, 0.1]
for j in range(len(arr)):
if profit_2 >= arr[j]:
print('j = ' + str(j) + '\n')
print(profit_2, arr[j])
bonus_2 = rat[j] * (profit_2 - arr[j])
print(str(bonus_2) + '=' + str(rat[j]) + '*' + '( '+ str(profit_2)+ '-' + str(arr[j]) + ') \n')
for k in range(j+1,6):
bonus_ = bonus_2
bonus_2 = bonus_2 + (arr[k-1] -arr[k]) * rat[k]
print('k = ' + str(k) + '\n')
print(str(bonus_2) + '='+ str(bonus_) + '+' + '( '+ str(arr[k-1])+ '-' + str(arr[k]) + ')' + '*' + str(rat[k]) + '\n')
break
print('your bouns_2 is :' + str(bonus_2))
'''
----------------------------以下是输出-------------------------
Show me your profit_0,and I will comulate your bouns_0: 100001
your bouns_0 is : 10000.075
Show me your profit_1,and I will comulate your bouns_1: 100001
your bouns_1 is : 10000.075
Show me your profit_2,and I will comulate your bouns_2: 100001
your bouns_2 is :10000.075