1. 程式人生 > >【每日一題】獎金問題

【每日一題】獎金問題

一:問題描述 二:問題分析

    涉及資料:利潤profit,獎金bonus     資料間的關係:當profit<=10w,bonus = profit *0.1;當profit<=20w, bonus = 100000*0.1 + (profit-100000)*0.075……
三:程式碼  
#由使用者輸入一個利潤,並將輸入轉換為整數型方便進行比較運算
profit = int(input('Please type in your profit(for example : 100000):'))
#將固定的獎金計算好方便之後直接使用
bonus1 = 100000*0.1
bonus2 = bonus1 + 100000*0.075
bonus3 = bonus2 + 200000*0.05
bonus4 = bonus3 + 200000*0.03
bonus5 = bonus4 + 400000*0.015
#對利潤數額進行比較
if profit <= 100000:
    bonus = profit*0.1
elif profit<=200000:
    bonus = bonus1 + (profit-100000)*0.075
elif profit<=400000:
    bonus = bonus2 + (profit-200000)*0.05
elif profit<=600000:
    bonus = bonus3 + (profit-400000)*0.03
elif profit<=1000000:
    bonus = bonus4 + (profit-600000)*0.015
else:
    bonus = bonus5 + (profit-1000000)*0.01
#輸出結果
print('Your bonus is : %d yuan'%bonus)

輸出結果: