實例002:「個稅計算」python
題目:企業發放的獎金根據利潤提成。利潤(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,求應發放獎金總數?編程
程序分析 分區間計算便可。code
while 1: #1與True相等,但1效率高 profit=int(input('Show me the money: ')) 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)): if profit<=thresholds[i]: bonus+=profit*rates[i] profit=0 break else: bonus+=thresholds[i]*rates[i] profit-=thresholds[i] bonus+=profit*rates[-1] print(bonus) #解本問題有多種方法,此方法並非標準答案,讀者能夠本身嘗試各類方法。
若是你喜歡個人文章,請滑到下方點個推薦再走. ,以給我動力哦;轉載請註名出處。而後..請多來作客鴨。input
注:陸續會更新。歡迎你們在評論區分享出大家的方案讓咱們一塊兒進步。it