zoukankan      html  css  js  c++  java
  • python 练习题练习题2--多分支选择

    题目:企业发放的奖金根据利润提成。利润(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,求应发放奖金总数?

    程序分析:请利用数轴来分界,定位。注意定义时需把奖金定义成长整型。

    我的源码(基于python3.6):

    # -*- coding:UTF-8 -*-
    #
    # 利润(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,求应发放奖金总数?


    I= int(input("pls input the profile:"))
    arr = [1000000,600000,400000,200000,100000,0]
    rat = [0.01,0.015,0.03,0.05,0.075,0.1]
    t=0
    if I<100000:
    t+=I*0.1
    elif I<=200000:
    t=100000*0.1+(I-100000)*0.075
    elif I<=400000:
    t = 100000 * 0.1 + 100000*0.075+(I - 200000) * 0.05
    elif I<=600000:
    t = 100000 * 0.1 + 100000 * 0.075 + 200000*0.05+(I - 400000) * 0.03
    elif I<=1000000:
    t = 100000 * 0.1 + 100000 * 0.075 + 200000*0.05+200000*0.03+(I - 600000) * 0.015
    else:
    t = 100000 * 0.1 + 100000 * 0.075 + 200000 * 0.05 + 200000 * 0.03 + 400000*0.015+(I - 1000000) * 0.01
    print(t)

    其他人的方式:

    #!/usr/bin/python
    # -*- coding: UTF-8 -*-
    
    import sys
    
    reload(sys)
    sys.setdefaultencoding('utf-8')
    
    x = int(raw_input("净利润:"))
    
    if x<=100000:
        bonus=x*0.1
        print u"奖金:",bonus,u"元"
    elif 100001<x<=200000:
        bonus=10000+(x-100000)*0.075
        print u"奖金:",bonus,u"元"
    elif 200001<x<=400000:
        bonus=10000+7500+(x-200000)*0.05
        print u"奖金:",bonus,u"元"
    elif 400001<x<=600000:
        bonus=10000+7500+10000+(x-400000)*0.03
        print u"奖金:",bonus,u"元"
    elif 600001<x<=1000000:
        bonus=10000+7500+10000+6000+(x-600000)*0.015
        print u"奖金:",bonus,u"元"
    elif 600001<x<=1000000:
        bonus=10000+7500+10000+6000+6000+(x-600000)*0.01
        print u"奖金:",bonus,u"元"
  • 相关阅读:
    docker 部署aps.net MVC到windows容器
    docker 搭建私有仓库 harbor
    解决关于:Oracle数据库 插入数据中文乱码 显示问号???
    ionic cordova build android error: commamd failed with exit code eacces
    cordova build android Command failed with exit code EACCES
    Xcode 10 iOS12 "A valid provisioning profile for this executable was not found
    使用remix发布部署 发币 智能合约
    区块链: 编译发布智能合约
    mac 下常用命令备忘录
    JQuery fullCalendar 时间差 排序获取距当前最近的时间。
  • 原文地址:https://www.cnblogs.com/gaochsh/p/6763640.html
Copyright © 2011-2022 走看看