Python編程練習題和答案實例二:關於數軸和長整型數據類型的練習。
阿新 • • 發佈:2018-01-12
for 利潤高 掌握 post pro 提問 編程 spa 100萬
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,求應發放獎金總數?
#我的笨辦法 profit = int(input(‘Profit=‘)) a = profit * 0.1 b = (profit - 100000) * 0.075 c = (profit - 200000) * 0.05 d= (profit - 400000) * 0.03 e = (profit - 600000) * 0.015 f = (profit - 1000000) * 0.01 if profit <= 100000: print(a) if 100000 < profit <= 200000: print(a + b) if 200000 < profit <= 400000: print(a + b + c) if 400000 < profit <= 600000: print(a + b + c + d) if 600000 < profit <= 1000000: print(a + b + c + d + e) if 1000000 < profit:print(a + b + c + d + e + f)
#答案算法,也算是明白了,要多練習掌握 a = [1000000, 600000, 400000, 200000, 100000, 0] b = [0.01, 0.015, 0.03, 0.05, 0.075, 0.1] profit = int(input(‘>>>‘)) bonus = 0 for i in range(6): if profit > a[i]: bonus += (profit - a[i]) * b[i] print(bonus)
Python編程練習題和答案實例二:關於數軸和長整型數據類型的練習。