小强森 发表于 2019-3-29 19:41:59

新手·ing 发表于 2017-3-24 22:17


确实是高手,看到数轴分界,定位就感觉和变通的IF语句叠加不同,代码相当高效!!!

阿摩leon 发表于 2019-4-22 18:34:21

temp = int(input('请输入:'))
a =0
if temp <= 10:
    a = temp*0.1
    print(a)
elif 10 < temp <=20:
    a = 1+(temp-10)*0.075
    print(a)
elif 20 < temp <=40:
    a =1.75+(temp-20)*0.05
    print(a)
elif 40 < temp <=60:
    a = 2.75+(temp-40)*0.03
    print(a)
elif 60 < temp <=100:
    a =3.35+(temp-60)*0.015
    print(a)
else:
    a =3.95 +(temp-100)*0.01
    print(a)

youyoudianzi 发表于 2019-4-23 14:31:18

NwkerWang 发表于 2017-5-25 12:04


第三行代码什么意思

yu123py 发表于 2019-4-26 16:07:11

p = int(input('please enter the profit:'))
if p <= 100000:
    r = p * 0.1
elif 100000 < p <= 200000:
    r = 10000 + (p - 100000) * 0.075
elif 200000 < p <= 400000:
    r = 10000 + 7500 + (p - 200000) * 0.05
elif 400000 < p <= 600000:
    r = 27500 + (p - 400000) * 0.03
elif 600000 < p <= 1000000:
    r = 33500 + (p - 600000) * 0.015
elif p > 1000000:
    r = 39500 + (p - 1000000) * 0.01
print(r)

陌小白 发表于 2019-4-29 14:56:47

while True:
    try:
      profit = int(input('请输入利润>'))
    except ValueError:
      print('您的输入有误,请重新输入')
    else:
      break

deduct, pro_num = 0, 0
while True:
    if profit <= 100000 or pro_num in :
      if pro_num in :
            deduct += 100000 * 0.1
            if pro_num == 1:
                break
      else:
            deduct = profit * 0.1
            break

    if 100000 < profit <= 200000 or pro_num in :
      if pro_num in :
            deduct += 100000 * 0.075
            if pro_num == 2:
                break
      else:
            pro_num = 1
            profit -= 100000
            deduct = profit * 0.075

    if 200000 < profit <= 400000 or pro_num in :
      if pro_num in :
            deduct += 200000 * 0.05
            if pro_num == 3:
                break
      else:
            pro_num = 2
            profit -= 200000
            deduct = profit * 0.05

    if 400000 < profit <= 600000 or pro_num in :
      if pro_num in :
            deduct += 200000 * 0.03
            if pro_num == 4:
                break
      else:
            pro_num = 3
            profit -= 400000
            deduct = profit * 0.03

    if 600000 < profit <= 1000000 or pro_num in :
      if pro_num in :
            deduct += 400000 * 0.03
            if pro_num == 5:
                break
      else:
            pro_num = 4
            profit -= 600000
            deduct = profit * 0.015

    if profit > 1000000:
      pro_num = 5
      profit -= 1000000
      deduct = profit * 0.01

print('最终提成为>', deduct)

感觉应该没有人写的比我还复杂了吧{:10_266:}

x287208793 发表于 2019-5-30 10:44:12

i = int(input('请输入月利润:'))
j = float()
while i:
    if 0 < i <= 10:
      j = 10
      print('月利润为:{0}万 ,奖金提成为:{1}%'.format(i,j))
      break
    elif 10 < i < 20:
      j = 7.5
      print('月利润为:{0}万 ,奖金提成为:{1}%'.format(i,j))
      break
    elif 20 <= i < 40:
      j = 5
      print('月利润为:{0}万 ,奖金提成为:{1}%'.format(i,j))
      break
    elif 40 <= i < 60:
      j = 3
      print('月利润为:{0}万 ,奖金提成为:{1}%'.format(i,j))
      break
    elif 60 <= j < 100:
      j = 1.5
      print('月利润为:{0}万 ,奖金提成为:{1}%'.format(i,j))
      break
    elif i >= 100:
      j = 1
      print('月利润为:{0}万 ,奖金提成为:{1}%'.format(i,j))
      break
    else:
      i = int(input('输入错误,请重新输入:'))

糠爸 发表于 2019-7-3 12:30:13

本帖最后由 糠爸 于 2019-7-3 12:34 编辑

小白一枚,请大师指教,先看看我的成长之路,贴出来后我会认真学习各位大神的代码,谢谢!

# 企业发放的奖金根据利润提成。利润(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 = input("请输入本期利润数额(金额精确到个位):")
temp1 = 100000
temp2 = 200000
temp3 = 400000
temp4 = 600000
temp5 = 1000000
profit = int(I)
bonus = 0

if 0 < profit <= temp1:
    step1 = profit*0.1
    bonus = int(step1)

elif temp1 < profit <= temp2:
        step1 = 100000 * 0.1
        step2 = step1 + (profit-temp1 ) *0.075
        bonus = step2

elif temp2 < profit <=temp3:
        step1 = 100000 * 0.1
        step2 = 100000 * 0.075
        step3 = step1 + step2 +(profit - temp2) * 0.05
        bonus = step3

elif temp3 < profit <=temp4:
        step1 = 100000 * 0.1
        step2 = 100000 * 0.075
        step3 = 200000 * 0.05
        step4 = step1 + step2 + step3 + (profit - temp3) * 0.03
        bonus = step4

elif temp4 < profit <= temp5:
        step1 = 100000 * 0.1
        step2 = 100000 * 0.075
        step3 = 200000 * 0.05
        step4 = 200000 * 0.03
        step5 = step1 + step2 + step3 + step4 + (profit - temp4) * 0.015
        bonus = step5

elif profit > temp5:
        step1 = 100000 * 0.1
        step2 = 100000 * 0.075
        step3 = 200000 * 0.05
        step4 = 200000 * 0.03
        step5 = 400000 * 0.015
        step6 = step1 + step2 + step3 + step4 + step5 +(profit - temp5) * 0.01
        bonus = step6

else:
        print("对不起,你没有对公司做贡献!")

print(bonus)
   
# 企业发放的奖金根据利润提成。利润(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 = input("请输入本期利润数额(金额精确到个位):")
temp0 = 0
temp1 = 100000
temp2 = 200000
temp3 = 400000
temp4 = 600000
temp5 = 1000000
profit = int(I)
base1 = 100000 * 0.1
base2 = 100000 * 0.075
base3 = 200000 * 0.05
base4 = 200000 * 0.03
base5 = 400000 * 0.015
step1 = 0.1
step2 = 0.075
step3 = 0.05
step4 = 0.03
step5 = 0.015
step6 = 0.01

if (profit - temp5) < 0:
        if (profit - temp4) < 0:
                if (profit - temp3) < 0:
                        if (profit - temp2) < 0:
                                if (profit - temp1) < 0:
                                        if (profit - temp0) <= 0:
                                                print('加油,公司期望你能做出更多贡献!')
                                                exit()
                                        bonus = profit * step1
                                        print(bonus)
                                        exit()
                                bonus = base1 + (profit - temp1) * step2
                                print(bonus)
                                exit()
                        bonus = base1 + base2 + (profit - temp2) * step3
                        print(bonus)
                        exit()
                bonus = base1 + base2 + base3 + (profit - temp3) * step4
                print(bonus)
                exit()
        bonus = base1 + base2 + base3 + base4 + (profit - temp4) * step5
        print(bonus)
        exit()
else:
        bonus = base1 + base2 + base3 + base4 + base5+(profit - temp5) * step6
        print(bonus)

小猪猪妍 发表于 2019-7-3 21:34:02

a=input('请输入当月利润:')
a=int(a)
if a<=100000:
    c=a*0.1
    print(c)
elif a>100000 and a<200000:
    c=a*0.1+(a-100000)*0.075
    print(c)
elif a>=200000 and a<400000:
    c=(a-200000)*0.05
    print(c)
elif a>=400000 and a<600000:
    c=(a-400000)*0.03
    print(c)
elif a>=600000 and a<1000000:
    c=(a-600000)*0.015
    print(c)
else :
    c=(a-1000000)*0.01
    print(c)

山岂乎不在高 发表于 2019-7-5 16:58:08

def jiangjin(n):


    m = 0
    if n > 100:
      a=n-100
      m += a*0.01
      n = 100
    if n > 60:
      a=n-60
      m += a*0.015
      n = 60
    if n > 40:
      a=n-40
      m += a*0.03
      n = 40
    if n > 20:
      a=n-20
      m += a*0.05
      n = 20
    if n > 10:
      a=n-10
      m += a*0.075
      n = 10
    if n > 0:
      m += n*0.1
    return m

if __name__ == '__main__':
    i = input("当年利润:")
    n=float(i)
    print('利润:',n,'奖金:',jiangjin(n))

panheng 发表于 2019-8-5 14:44:51

'''题目:企业发放的奖金根据利润提成。利润(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:数据由高向低逐层计算
def answer1():
    profits = float(input("请输入利润金额(万元):"))
    bonus = 0
    if profits > 100:
      bonus += (profits - 100) * 0.01
      profits = 100
    elif profits > 60:
      bonus += (profits - 60) * 0.015
      profits = 60
    elif profits >40:
      bonus += (profits - 40) * 0.03
      profits = 40
    elif profits > 20:
      bonus += (profits - 20) * 0.05
      profits = 20
    elif profits > 10:
      bonus += (profits - 10) * 0.075
      profits = 10
    bonus += profits * 0.1
    print("应发放的奖金为%d元" % (bonus*10000))

#解法2:利用迭代方法
def answer2():
    list1 =    #金额分级阶梯
    list2 = #相应利率
    profits = float(input("请输入利润金额(万元):"))
    bonus = 0
    for each in list1:
      if profits > each:
            bonus += (profits - each) * list2
            profits = each
    print("应发放的奖金为{}元".format(bonus*10000))



if __name__ == "__main__":
    answer1()
    answer2()

henry2018 发表于 2019-9-5 17:16:54

i = int(input("奖金(单位:万):"))
j = 0
if i > 100:
    x = i - 100
    j += x * 1.01
    i -= x
if i <= 100:
    x = i - 60
    j += x * 1.015
    i -= x
if i <= 60:
    x = i - 40
    j += x * 1.03
    i -= x
if i <= 40:
    x = i - 20
    j += x * 1.05
    i -= x
if i <= 20:
    x = i - 10
    j += x * 1.075
    i -= x
if i <= 10:
    x = i - 0
    j += x * 1.1
    i -= x

print(j)

beirry 发表于 2019-10-29 07:58:17

I = int(input("请输入纯利润(万):"))
if I <= 10:
   money = I * 0.1 + I
elif 10 < I <= 20:
   money = 10 * 0.1 + (I - 10) * 0.075 + I
elif 20 < I <= 40:
   money = (I - 20) * 0.05 + I
elif 40 < I <= 60:
   money = (I - 40) * 0.03 + I
elif 60 < I <= 100:
   money = (I - 60) * 0.015 + I
elif I >= 100:
   money = (I - 100) * 0.01
print("当月应发放奖金总数为:%s" % money)

lovesdczy 发表于 2019-11-5 16:46:40

#10万元提成
a=100000*0.1
#10-20万元提成
b=100000*0.075
#20-40万元提成
c=200000*0.05
#40-60万元提成
d=200000*0.03
#60-100万元提成
e=400000*0.015
while True:
    I=float(input("请输入利润:"))
    if I>1000000 :
      result=a+b+c+d+e+(I-1000000)*0.01
      print(result)
    elif I>600000 and I<=1000000 :
      result=a+b+c+d+(I-600000)*0.015
      print(result)
    elif I>400000 and I<=600000 :
      result=a+b+c+(I-400000)*0.03
      print(result)
    elif I>200000 and I<=400000:
      result=a+b+(I-200000)*0.05
      print(result)
    elif I>100000 and I<=200000 :
      result=a+(I-100000)*0.075
      print(result)
    elif I>0 and I<=100000 :
      result=I*0.1
      print(result)
    else:
      print("输入有误!")

Jung 发表于 2019-11-20 08:45:14


info = input('Please enter the benifit:')
while info != 'Quit':
    Benifit =float(info)
    if Benifit<=100000:
      Bonus = Benifit*0.1
      print(Bonus)
    elif(Benifit in range(100000,200000)):
      Bonus = 100000*0.1 + (Benifit-100000)*0.075
      print(Bonus)
    elif(Benifit in range(200000,400000)):
      Bonus = 100000*0.175 + (Benifit-200000)*0.05
      print(Bonus)
    elif(Benifit in range(400000,600000)):
      Bonus = 100000*0.175 + 200000*0.05 +(Benifit-200000)*0.03
      print(Bonus)
    elif(Benifit in range(600000,1000000)):
      Bonus = 100000*0.175 + 200000*(0.05 +0.03) + (Benifit-600000)*0.015
      print(Bonus)
    elif(Benifit >1000000)):
      Bonus = 100000*0.175 + 200000*(0.05 +0.03) + 400000*0.015 +(Benifit-1000000)*0.01
      print(Bonus)
    info = input('Please enter the benifit:')

Python学好 发表于 2019-12-9 20:15:48

lr=input ('请输入您的利润:')
lr=float (lr)
if 0<=lr<=10:
    jj=lr*0.1
elif 10<lr<=20:
    jj=10*0.1+(lr-10)*0.075
elif 20<lr<=40:
    jj=10*0.1+10*0.075+(
      lr-20)*0.05
elif 40<lr<=60:
    jj=10*0.1+10*0.075+(40-20)*0.05+(lr-40)*0.03
elif 60<lr<=100:
    jj=10*0.1+10*0.075+(40-20)*0.05+(60-40)*0.03+(lr-60)*0.015
elif lr>100:
    jj=10*0.1+10*0.075+(40-20)*0.05+(60-40)*0.03+(100-60)*0.015+(lr-100)*0.01
print(jj)
jj=str(jj)
print('您的奖金为'+jj+'万元!')

Yl10 发表于 2020-1-9 18:52:11

profit=int(input('请输入当月的利润(元):'))
if profit <= 100000:
    bouns = profit * 0.1
elif 100000 < profit <= 200000:
    bouns=10000+(profit-100000)*0.75
elif 200000 < profit <= 400000:
    bouns = 8500 + (profit - 200000) * 0.5
elif 400000 < profit <= 600000:
    bouns = 18500 + (profit - 400000) * 0.3
elif 600000 < profit <= 1000000:
    bouns = 24500 + (profit - 600000) * 0.15
else:
    bouns = 31300 + (profit - 1000000) * 0.1
print('当月的奖金为:',bouns,'元')

ka233siji 发表于 2020-1-16 09:42:54

profit = int(input('利润:(单位为万元)'))
bonus = 0   
if profit>100 :
    bonus = (profit-100)/100
    profit = 100
if 60<profit<=100 :
    bonus += (profit-60)*0.015
    profit = 60
if 40<profit<=60 :
    bonus += (profit-40)*0.03
    profit = 40
if 20<profit<=40 :
    bonus += (profit-20)*0.05
    profit = 20
if 10<profit<=20 :
    bonus += (profit-10)*0.075
    profit = 10
if 0<=profit<=10 :
    bonus += profit/10
print(bonus)

lollipop1211 发表于 2020-2-14 12:14:45

profit=int(input('当月利润为(单位为万元):'))
if profit in range(0,11):
    print(profit*0.1,'万元')
elif profit in range(10,21):
    print(10*0.1+(profit-10)*0.075,'万元')
elif profit in range(20,41):
    print(10*0.1+10*0.075+(profit-20)*0.05,'万元')
elif profit in range(40,61):
    print(10*0.1+10*0.075+20*0.05+(profit-40)*0.03,'万元')
elif profit in range(60,101):
    print(10*0.1+10*0.075+20*0.05+20*0.03+(profit-60)*0.015,'万元')
else:
    print(10*0.1+10*0.075+20*0.05+20*0.03+40*0.015+(profit-100)*0.01,'万元')

君子好逑 发表于 2020-2-24 13:33:18

a=100000*0.1
b=100000*0.075
c=200000*0.05
d=200000*0.03
e=400000*0.015
temp=input('请输入利润额:(单位:元)')
while not temp.isdigit():
    print("抱歉,输入不合法!!!")
    temp=input("请重新输入利润额:(单位:元)")
profit=int(temp)
if(profit<=100000):
    bonus=profit*0.1
elif(profit<=200000):
    bonus=a+(profit-100000)*0.075
elif(profit<=400000):
    bonus=a+b+(profit-200000)*0.05
elif(profit<=600000):
    bonus=a+b+c+(profit-400000)*0.03
elif(profit<=1000000):
    bonus=a+b+c+d+(profit-600000)*0.015
else :
    bonus=a+b+c+d+e+(profit-1000000)*0.001
print("应发放的奖金为:%d"%bonus)

bwlinux 发表于 2020-3-1 17:16:31

profitx = float(input('请输入企业利润:'))

if profitx <= 100000:
    bonus0 = profitx * 0.1
    bonus = bonus0
elif profitx <= 200000 and profitx > 100000:
    bonus0 = 100000 * 0.1
    bonus1 = (profitx - 100000) * 0.075
    bonus = bonus0 + bonus1
elif profitx <= 400000 and profitx > 200000:
    bonus0 = 100000 * 0.1
    bonus1 = 100000 * 0.075
    bonus2 = (profitx - 2000000) * 0.005
    bonus = bonus0 + bonus1 + bonus2
elif profitx <=600000 and profitx >400000:
    bonus0 = 100000 * 0.1
    bonus1 = 100000 * 0.075
    bonus2 = 2000000 * 0.005
    bonus3 = (profitx - 4000000) * 0.003
    bonus = bonus0 + bonus1 + bonus2 + bonus3
elif profitx <=1000000 and profitx > 600000:
    bonus0 = 100000 * 0.1
    bonus1 = 100000 * 0.075
    bonus2 = 2000000 * 0.005
    bonus3 = 2000000 * 0.003
    bonus4 = (profitx - 6000000) * 0.00015
    bonus = bonus0 + bonus1 + bonus2 + bonus3 + bonus4
elif profitx > 1000000:
    bonus0 = 100000 * 0.1
    bonus1 = 100000 * 0.075
    bonus2 = 2000000 * 0.005
    bonus3 = 2000000 * 0.003
    bonus4 = 4000000 * 0.00015
    bonus5 = (profitx -600000) * 0.0001
    bonus = bonus0 + bonus1 + bonus2 + bonus3 + bonus4 +bonus5

print('奖金总数为:%.2f' % bonus)
页: 1 2 3 4 5 [6] 7
查看完整版本: Python:每日一题 2