Python 100 練習-2 計算分紅(參考 runoob )

計算分紅

比分紅百分比會依照達標的標準發放,基本分紅為 0.1

例如業績25萬,

標準0.1 獎金%10,000 

符合100,000 0.075 獎金$7500 

符合200,000 0.05 獎金$2500總分紅金額為:20,000

i = int(input('營業額:'))
arr = [1000000,600000,400000,200000,100000,0]
rat = [0.01,0.015,0.03,0.05,0.075,0.1]
r = 0

for idx in range(0,6):
    if i>arr[idx]:
        r+=(i-arr[idx])*rat[idx]
        print (rat[idx])
        print ((i-arr[idx])*rat[idx])
        i=arr[idx]
print ('分紅=',r)
營業額:250000 (輸入的營業額)
0.05 (符合200,000分紅)
2500.0
0.075 (符合100,000分紅)
7500.0
0.1  (基本分紅)
10000.0
總分紅= 20000.0