天天看點

執行個體002:“個稅計算” 企業發放的獎金根據利潤提成。利潤(I)低于或等于10萬元時,獎金可提10%;利潤高于10萬元,低于20萬元時,低于10萬元的部分按10%提成,高于10萬元的部分,可提成7.

執行個體002:“個稅計算”

# **題目:**企業發放的獎金根據利潤提成。

# 利潤(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,求應發放獎金總數?

#題目分析

"""

當我們進行手算的時候,是這樣算的:假設是1500000,是大于10000萬的,下面我們來是手算:

10w*0.1+10w*0.075+20w*0.05+20w*0.03+40w*0.015+50w*0.01

"""

# **程式分析:**分區間計算即可

for j in range(10):  # 可以測試10次
    profit = int(input('請輸入你的利潤金額: '))  #input輸入的是字元串類型,要用int()轉為整數
    bonus = 0
    thresholds = [100000, 100000, 200000, 200000, 400000]  # 分區間計算
    rates = [0.1, 0.075, 0.05, 0.03, 0.015, 0.01]
    for i in range(len(thresholds)):

        print(profit, "--", i, "thresholds[i]", thresholds[i], "rates[i]", rates[i])

        if profit <= thresholds[i]:
            bonus += profit * rates[i]
            profit = 0
            break
        else:
            bonus += thresholds[i] * rates[i]
            profit -= thresholds[i]
        print(profit)
    bonus += profit * rates[-1]  # 這裡就是計算高于100w部分的獎金
    print(" 發放的獎金總數為: ", bonus)      
請輸入你的利潤金額: 1500000
1500000 -- 0 thresholds[i] 100000 rates[i] 0.1
1400000
1400000 -- 1 thresholds[i] 100000 rates[i] 0.075
1300000
1300000 -- 2 thresholds[i] 200000 rates[i] 0.05
1100000
1100000 -- 3 thresholds[i] 200000 rates[i] 0.03
900000
900000 -- 4 thresholds[i] 400000 rates[i] 0.015
500000
 發放的獎金總數為:  44500.0      

繼續閱讀