新聞中心
今天主要分享一個python實例,大家有興趣也可以做一下~

成都創(chuàng)新互聯(lián)公司長期為上千余家客戶提供的網(wǎng)站建設(shè)服務(wù),團(tuán)隊從業(yè)經(jīng)驗10年,關(guān)注不同地域、不同群體,并針對不同對象提供差異化的產(chǎn)品和服務(wù);打造開放共贏平臺,與合作伙伴共同營造健康的互聯(lián)網(wǎng)生態(tài)環(huán)境。為靈臺企業(yè)提供專業(yè)的網(wǎng)站建設(shè)、成都做網(wǎng)站,靈臺網(wǎng)站改版等技術(shù)服務(wù)。擁有10多年豐富建站經(jīng)驗和眾多成功案例,為您定制開發(fā)。
需求
企業(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%提成,從鍵盤輸入當(dāng)月利潤I,求應(yīng)發(fā)放獎金總數(shù)?
思路
分區(qū)間計算即可。
實現(xiàn)腳本:
1. JAVA代碼
- public class 根據(jù)提成發(fā)放獎金 { public static void main(String[] args) { System.out.print("請輸入利潤金額:"); Scanner in = new Scanner(System.in); double bonus = 0; //獎金 double profit = in.nextDouble(); //利潤 in.close(); if(profit<=0) { System.out.println("輸入錯誤"); } else if(profit > 0 && profit <= 10) { //小于10萬 bonus = profit * 0.1; } else if(profit > 10 && profit <20) { //10-20萬 bonus = (profit-10) * 0.075 + 1; } else if(profit >=20 && profit <40) { //20-40萬 bonus = (profit-20)*0.05 + 1.75; } else if(profit >=40 && profit < 60) { //40-60萬 bonus = (profit-40)*0.03 + 2.75; } else if(profit >=60 && profit < 100) { //60-100萬 bonus = (profit-60)*0.015 + 3.35; } else { bonus = (profit-100)*0.001 + 3.95; //大于100萬 } System.out.println("獎金為:"+ (bonus*10000) +"元"); }}
2. python代碼
- #!/usr/bin/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%提成,從鍵盤輸入當(dāng)月利潤I,求應(yīng)發(fā)放獎金總數(shù)?profit=int(input('請輸入利潤金額:\n'))bonus=0thresholds=[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=0breakelse:bonus+=thresholds[i]*rates[i]profit-=thresholds[i]bonus+=profit*rates[-1]print('利潤提成金額:%f' %bonus)
按F5輸出結(jié)果:
如何讓sublime支持帶input()的python程序
1. python文件的界面里點(diǎn)擊上方菜單欄的tools->sublimeREPL->python->python run current file,這時候就像IDLE一樣,會彈出一個新的窗口,而且是可交互的,可以輸入。(這個操作相當(dāng)于點(diǎn)了下“run”,執(zhí)行代碼,不過每次都要這樣,太麻煩,可以按下面的方法,設(shè)置快捷鍵)
2. 設(shè)置快捷鍵,打開preferences->Key Binding-User,寫入以下內(nèi)容
- [ { "keys": ["f5"], "caption": "SublimeREPL:Python", "command": "run_existing_window_command", "args":{"id": "repl_python_run", "file": "config/Python/Main.sublime-menu" } }]
分享文章:Python每日一練之如何計算你的應(yīng)發(fā)獎金?
URL地址:http://m.fisionsoft.com.cn/article/dhspogg.html


咨詢
建站咨詢
