Python每日一练之如何计算你的应发奖金?

今天主要分享一个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"                            }     }] 

亿华云
滇ICP备2023000592号-31