Skip to main content
 Web开发网 » 编程语言 » Python语言

分享一个实用的python脚本--计算你的奖金

2021年11月28日7450百度已收录

概述今天主要分享一个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=0 break else: bonus+=thresholds[i]*rates[i] profit-=thresholds[i]bonus+=profit*rates[-1]print('利润提成金额:%f' %bonus)

分享一个实用的python脚本--计算你的奖金  Python脚本 第1张

按F5输出结果:

分享一个实用的python脚本--计算你的奖金  Python脚本 第2张

分享一个实用的python脚本--计算你的奖金  Python脚本 第3张

分享一个实用的python脚本--计算你的奖金  Python脚本 第4张

分享一个实用的python脚本--计算你的奖金  Python脚本 第5张

分享一个实用的python脚本--计算你的奖金  Python脚本 第6张

如何让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" } }]分享一个实用的python脚本--计算你的奖金  Python脚本 第7张

觉得有用的朋友多帮忙转发哦!后面会分享更多devops和DBA方面的内容,感兴趣的朋友可以关注下~

分享一个实用的python脚本--计算你的奖金  Python脚本 第8张

评论列表暂无评论
发表评论
微信