Python:每日一题002
生活随笔
收集整理的這篇文章主要介紹了
Python:每日一题002
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
?
題目:
企業(yè)發(fā)放的獎金根據(jù)利潤提成。利潤(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,求應(yīng)發(fā)放獎金總數(shù)?
程序分析:
請利用數(shù)軸來分界,定位。注意定義時需把獎金定義成長整型。
?
個人解題思路:用if-elif 多分支處理
?
while True:profit = input("請輸入利潤: (單位:萬元)\n").strip()if not profit:continueif not profit.isdigit():print("您的輸入有誤!請重新輸入。")continueelse:profit = eval(profit)bonus_a,bonus_b,bonus_c,bonus_d,bonus_e = 10*0.1,10*0.075,20*0.05,20*0.03,40*0.015bonus_list = [bonus_a,bonus_b,bonus_c,bonus_d,bonus_e]if profit > 100:bonus = (profit - 100) * 0.01 + sum(bonus_list)elif profit > 60:bonus = (profit - 60) *0.015 + sum(bonus_list[:-1])elif profit > 40:bonus = (profit - 40) *0.03 + sum(bonus_list[:-2])elif profit > 20:bonus = (profit - 20) *0.05 + sum(bonus_list[:-3])elif profit > 10:bonus = (profit - 10) *0.075 + sum(bonus_list[:-4])elif profit > 0:bonus = profit *0.1else:print("沒利潤,沒有獎金!")continueprint("獎金是%s萬元"%bonus)其他解題參考:
?
money = int(input("輸入利潤:")) rat = [0.01,0.015,0.03,0.05,0.075,0.1] level = [100,60,40,20,10,0] s = 0 for i in range(6):if money-level[i]>0:s += (money-level[i])*rat[i]money = level[i] print (s)
?
?(本文編號002,首發(fā)于2018年9月12日)
轉(zhuǎn)載于:https://www.cnblogs.com/Nicholas0707/p/9638063.html
總結(jié)
以上是生活随笔為你收集整理的Python:每日一题002的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: resetroot_169route_p
- 下一篇: Python3的unittest用例按编