python每日一練之如何計算你的應發獎金?

2020-01-07     波波說運維

概述

今天主要分享一個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,求應發放獎金總數?


思路

分區間計算即可。


實現腳本:

1、JAVA代碼

public class   根據提成發放獎金 {    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%提成,從鍵盤輸入當月利潤I,求應發放獎金總數?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輸出結果:





如何讓sublime支持帶input()的python程序

1、python文件的介面里點擊上方菜單欄的tools->sublimeREPL->python->python run current file,這時候就像IDLE一樣,會彈出一個新的窗口,而且是可交互的,可以輸入。(這個操作相當於點了下「run」,執行代碼,不過每次都要這樣,太麻煩,可以按下面的方法,設置快捷鍵)

2、設置快捷鍵,打開preferences->Key Binding-User,寫入以下內容

[       { "keys": ["f5"],           "caption": "SublimeREPL:Python",              "command": "run_existing_window_command",             "args":{"id": "repl_python_run",                                 "file": "config/Python/Main.sublime-menu"                            }     }]



覺得有用的朋友多幫忙轉發哦!後面會分享更多devops和DBA方面的內容,感興趣的朋友可以關注下~


文章來源: https://twgreatdaily.com/JmomfW8BMH2_cNUgSRcn.html