100個不同型別的python語言趣味編程題
實體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,求應發放獎金總數?
程式分析 磁區間計算即可,
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)
#解本問題有多種方法,此方法并不是標準答案,讀者可以自己嘗試各種方法,
如果你喜歡我的文章,請滑到下方點個推薦再走. ,以給我動力哦;轉載請注名出處,然后..請多來做客鴨,
注:陸續會更新,歡迎大家在評論區分享出你們的方案讓我們一起進步,
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/176797.html
標籤:Python
上一篇:六角形的繪制
下一篇:破解字體加密
