实例002:“个税计算”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,求应发放奖金总数?编程
程序分析 分区间计算便可。code
while 1: #1与True相等,但1效率高 profit=int(input('Show me the money: ')) bonus=0 thresholds=[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(bonus) #解本问题有多种方法,此方法并非标准答案,读者能够本身尝试各类方法。
若是你喜欢个人文章,请滑到下方点个推荐再走. ,以给我动力哦;转载请注名出处。而后..请多来作客鸭。input
注:陆续会更新。欢迎你们在评论区分享出大家的方案让咱们一块儿进步。it