一步半个脚印 发表于 2018-8-21 17:37:20

x= int(input('please input your profit number (the unit is ten thousand):' ))
y=0
if x <= 10 :
        y = x * 0.1
elif 10 <x <= 20 :
        y= (x-10)*0.075+10*0.1
elif 20<x<=40:
        y=(x-20)*0.05+(x-10)*0.075+10*0.1
elif 40<x<=60:
        y=(x-40)*0.03+(x-20)*0.05+(x-10)*0.075+10*0.1
elif 60<x<=100:
        y=(x-60)*0.015+(x-40)*0.03+(x-20)*0.05+(x-10)*0.075+10*0.1
elif 100 < x :
        y=(x-100)*0.01+(x-60)*0.015+(x-40)*0.03+(x-20)*0.05+(x-10)*0.075+10*0.1

print(y)


上传代码格式。。嘻嘻。

acgods 发表于 2018-8-23 10:18:05

本帖最后由 acgods 于 2018-8-23 10:22 编辑

MonthProfit = int(input("请输入当月的利润:"))
prize = 0
def prize(MonthProfit):
    if MonthProfit <= 100000:
      prize = MonthProfit * 0.1
    elif 100000 < MonthProfit <= 200000:
      prize = 100000 * 0.1 + (MonthProfit - 100000)* 0.075
    elif 200000 < MonthProfit <= 400000:
      prize = 100000 * 0.1 + 100000 * 0.075 + (MonthProfit - 200000) * 0.05
    elif 400000 < MonthProfit <= 600000:
      prize = 100000 * 0.1 + 100000 * 0.075 + 200000 * 0.05 + (MonthProfit -400000) * 0.03
    elif 600000 < MonthProfit <= 1000000:
      prize = 100000 * 0.1 + 100000 * 0.075 + 200000 * 0.05 + 200000 * 0.03 + (MonthProfit - 600000) * 0.015
    else:
      prize = 100000 * 0.1 + 100000 * 0.075 + 200000 * 0.05 + 200000 * 0.03 + 400000 * 0.015 + (MonthProfit - 1000000) * 0.01
    return prize

print("本月的奖金为:" + str(prize(MonthProfit)))

FishC_TYRANT 发表于 2018-8-30 18:55:18

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


比我想的简洁,楼主大佬

god圣锋 发表于 2018-9-3 13:51:16

def pr(proft):
    #利润(I)低于或等于10万元时,奖金可提10%
    bonus = proft + proft*0.1

    '''利润高于10万元,低于20万元时,低于10万元的部分按10%提成,
    高于10万元的部分,可提成7.5%'''
    bonus2 = bonus + (proft - 10E+4)* 0.075

    #20万到40万之间时,高于20万元的部分,可提成5%
    bonus3 = bonus2 + (proft - 2*(10E+4))* 0.05

    #40万到60万之间时高于40万元的部分,可提成3%
    bonus4 = bonus3 + (proft - 4*(10E+4))* 0.03

    #60万到100万之间时,高于60万元的部分,可提成1.5%
    bonus5 = bonus4 + (proft - 6*(10E+4))* 0.015

    #高于100万元时,超过100万元的部分按1%提成
    bonus6 = bonus5 + (proft - 10E+5)* 0.01

    return bonus,bonus2,bonus3,bonus4,bonus5,bonus6

while True:
    proft = input('请输入当月的总利润')

    if proft == '.w':
      break
   
    proft = int(proft)
   
    bonus,bonus2,bonus3,bonus4,bonus5,bonus6 = pr(proft)
   
    if (proft > 10E+5):
      print(bonus6)

    elif proft > 6*(10E+4):
      print(bonus5)

    elif proft > 4*(10E+4):
      print(bonus4)

    elif proft > 2*(10E+4):
      print(bonus3)

    elif proft > 10E+4:
      print(bonus2)

    else:
      print(bonus)

_玛莎_ 发表于 2018-9-13 17:59:10

i = int(input('请输入当月的利润(单位:万元):'))
if i <= 10:
    bonus = i * 0.1
    print('应发奖金数为%s' % bonus)
elif 10 <= i <= 20:
    bonus = 10*0.1+(i-10)*0.075
    print('应发奖金数为%s' % bonus)
elif 20 <= i <= 40:
    bonus = 10*0.1+10*0.075+(i-20)*0.05
    print('应发奖金数为%s' % bonus)
elif 40 <= i <= 60:
    bonus = 10*0.1+10*0.075+20*0.05+(i-40)*0.03
    print('应发奖金数为%s' % bonus)
elif 60 <= i <= 100:
    bonus = 10*0.1+10*0.075+20*0.05+20*0.03+(i-60)*0.015
    print('应发奖金数为%s' % bonus)
else:
    bonus = 10*0.1+10*0.075+20*0.05+20*0.03+40*0.015+(i-100)*0.01
    print('应发奖金数为%s' % bonus)

whoam1python 发表于 2018-9-18 11:14:49

jj = 0
fl =
ll =
lr = int(input("请输入利润:"))
for i in range(6):
    if lr > fl:
      jj += (lr - fl) * ll
      print(jj)
      lr = fl

print(jj)

liujian973 发表于 2018-10-6 23:01:02

bonus_list={100000:,200000:,400000:,600000:,1000000:}
def money(profit,bonus_list=bonus_list):
    profit_section =
    if profit_section ==[]:
      return profit*0.1
    else:
      temp =]+ bonus_list]
       
      return (profit-temp)*temp+temp
try:
    i=int(input("请输入利润"))
    print(money(i)
except:print("请输入正确的利润")

zhangjk19841984 发表于 2018-10-18 14:45:26

profit=int(input('请输入当前的公司利润:--->'))
money=0
p=profit
m=money
if p<10:
    m=p*0.1
elif 10<=p<20:
    m=(p-10)*0.075+10*0.1
elif 20<=p<40:
    m=(p-20)*0.05+10*0.175
elif 40<=p<60:
    m=20*0.05+10*0.175+(p-40)*0.03
print(m)

丽啊DDer 发表于 2018-10-21 20:17:07

渡漫 发表于 2017-5-21 20:43
小弟不才

就服你!

小明禅师 发表于 2018-11-28 14:04:00

profit = int(input("输入净利润:"))
bouns=0.0

if(profit<=100000):
    bouns=profit*0.1
elif(100000<profit<=200000):
    bouns=100000*10/100+(profit-100000)*7.5/100
elif(200000<profit<=400000):
    bouns=100000*10/100 + 100000*7.5/100 + (profit-200000)*5/100
elif(400000<profit<=600000):
   bouns=100000*10/100 + 100000*7.5/100 + 200000*5/100 + (profit-400000)*3/100
elif(600000<profit<=1000000):
   bouns=100000*10/100 + 100000*7.5/100 + 200000*5/100 + 200000*3/100 + (profit-600000)*1.5/100
elif(profit>1000000):
   bouns=100000*10/100 + 100000*7.5/100 + 200000*5/100 + 200000*3/100 + 600000*1.5/100 + (profit-1000000)*1/100

print("奖金为:",bouns)

double-lee 发表于 2018-12-3 16:00:05

profit = float(input("输入当月利润: "))
bonus = 0
while profit:
    if profit <= 100000:
      bonus += profit * 0.1
      break
    elif 100000 < profit <= 200000:
      bonus += (profit - 100000) * 0.075
      profit = 100000
    elif 200000 < profit <= 400000:
      bonus += (profit - 200000) * 0.05
      profit = 200000
    elif 400000 < profit <= 600000:
      bonus += (profit - 400000) * 0.03
      profit = 400000
    elif 600000 < profit <= 1000000:
      bonus += (profit - 600000) * 0.015
      profit = 600000
    elif profit > 1000000:
      bonus += (profit - 1000000) * 0.01
      profit = 1000000
print("当月利润 %d ,应发放奖金总数为: %d"%(profit,bonus))

看了楼主的,再看自己的,太复杂了..{:10_260:}

sunrise085 发表于 2018-12-19 14:11:41

本帖最后由 sunrise085 于 2018-12-19 14:12 编辑

对于多次if...else...判断就不写了。我写了三个版本,第一个版本中有三个列表,分别是利润数轴列表、奖金比例列表、分段奖金列表,程序先判断利润在哪个区间,然后去查表计算总奖金。
mylist1 =
mylist2 =
mylist3 =
I = input('请输入当前月利润I:')
I = int(I)
for i in range(0,len(mylist1)):
        if I > mylist1:
                break
fee = (I-mylist1) * mylist2+mylist3
print ('奖金总数:',fee)

第二个版本中有两个列表,分别是利润数轴列表、奖金比例列表,直接循环计算总奖金。
mylist1 =
mylist2 =
I = 150000#input('请输入当前月利润I:')
temp = int(I)
fee = 0
for i in range(0,len(mylist1)):
        if temp > mylist1:
                fee += (temp-mylist1) * mylist2
                temp = mylist1
print ('奖金总数:',fee)
第三个版本是将第二个版本进行改进,利用函数写了一个递归,通过递归函数计算总奖金。
def fee(I):
        mylist1 =
        mylist2 =
        for i in range(0,len(mylist1)):
                if I > mylist1:
                        fees = (I - mylist1) * mylist2 + fee(mylist1)
                        break
        if I == 0:
                return 0
        return fees

I = input('请输入当前月利润I:')
temp = int(I)
print ('奖金总数:',fee(I))

nnxiaod 发表于 2018-12-31 13:46:29

def do1(a):
    if a <= 100000L:
      return a * 0.1
    elif 100000L < a <= 200000L:
      return (a - 100000L) * 0.075 + do1(100000L)
    elif 200000L < a <= 400000L:
      return (a - 200000L) * 0.05 + do1(200000L)
    elif 400000L < a <= 600000L:
      return (a - 400000L) * 0.03 + do1(400000L)
    elif 600000L < a <= 1000000L:
      return (a - 600000L) * 0.015 + do1(600000L)
    else:
      return (a - 1000000L) * 0.01 + do1(1000000L)


if __name__ == '__main__':
    a = input("请输入利润:")
    print(do1(long(a)))

梦星 发表于 2019-2-6 21:14:55

i = int(input('请输入您的利润:'))

bouns = 0


if i > 1e6:
    bouns += (i - 1e6) * 0.010
    i = 1e6
if i > 6e5:
    bouns += (i - 6e5) * 0.015
    i = 6e5
if i > 4e5:
    bouns += (i - 4e5) * 0.030
    i = 4e5
if i > 2e5:
    bouns += (i - 2e5) * 0.050
    i = 2e5
if i > 1e5:
    bouns += (i - 1e5) * 0.075
    i = 1e5
if i <= 1e5:
    bouns += i * 0.100

print(bouns)

iloverisa5206 发表于 2019-2-10 23:52:07

i=float(input('請輸入當月利潤:'))
if i<=100000:
    (i*0.1)=x
    print(x)
if i>100000:
    ((i-100000)*0.75+x)=y
    print(y)
if i>200000:
    ((i-200000)*0.05+y)=z
    print(z)
if i>400000:
    ((i-400000)*0.03+z)=a
if i>600000:
    ((i-600000)*0.15+a)=s
if i>1000000:
    ((i-1000000)*0.01+s)=d
    print(d)

為什麼一直語法錯誤

Xna_MT 发表于 2019-2-19 22:57:17


temp = input ('请输入当月利润数据(单位万元):')
x= float(temp)
y=0
if x<=10:
   y=x*0.1
   print('奖金为',y*10000,'元')
elif 10<x<=20:
    y=(x-10)*0.1+x*0.075
    print('奖金为',y*10000,'元')
elif 20<x<=40:
    y=(x-20)*0.05+(x-10)*0.1+x*0.075
    print('奖金为',y*10000,'元')
elif 40<x<=60:
    y=x*0.03+(x-20)*0.05+(x-10)*0.1+x*0.075
    print('奖金为',y*10000,'元')
elif 60<x<=100:
    y=x*0.015+(x-20)*0.05+(x-10)*0.1+x*0.075
    print('奖金为',y*10000,'元')
elif 100<x:
    y=x*0.01+(x-20)*0.05+(x-10)*0.1+x*0.075
    print('奖金为',y*10000,'元')
else:

    print('输入有误')#---还缺少异常捕抓
   

Sneakerjj 发表于 2019-3-1 14:44:12

i=int(input('当月利润:'))
if i <= 10:
    bonuses = i * 0.1
elif 10 < i <= 20:
    bonuses = 1 + (i - 10) * 0.075
elif 20 < i <= 40:
    bonuses = 1 + 0.75 + (i - 20) * 0.05
elif 40 < i <= 60:
    bonuses = 1 + 0.75 + 0.5 + (i - 20) * 0.03
elif 60 < i <= 100:
    bonuses = 1 + 0.75 + 0.5 + 0.3 + (i - 20) * 0.015
elif i > 100:
    bonuses = 1 + 0.75 + 0.5 + 0.3 + 0.15 + (i - 20) * 0.01
else:
    bonuses = 0
   
print('当月利润:%d'%i)
print('应发放奖金总数:' ,bonuses)

lwy520 发表于 2019-3-6 20:22:39

def jiangjical(lirun):
    jiangjin=0
    lirun_sheng=lirun
    while(True):
      if lirun_sheng <= 100000:
            jiangjin += lirun_sheng * 0.1
            break
      
      elif 100000 < lirun_sheng <= 200000:
            jiangjin += (lirun_sheng-100000) * 0.075
            lirun_sheng=100000

      elif 200000 < lirun_sheng <= 400000:
            jiangjin += (lirun_sheng-200000) * 0.05
            lirun_sheng=200000

      elif 400000 < lirun_sheng <= 600000:
            jiangjin += (lirun_sheng-400000) * 0.03
            lirun_sheng=400000

      elif 600000 < lirun_sheng <= 1000000:
            jiangjin += (lirun_sheng-600000) * 0.015
            lirun_sheng=600000

      else:
            jiangjin += (lirun_sheng-1000000) * 0.001
            lirun_sheng=1000000

    return jiangjin

lirun=int(input("请输入月利润:"))
jiangjin=jiangjical(lirun)
print(jiangjin)

苍月枫 发表于 2019-3-7 22:47:38

j = 0
i = int(input('请输入该月利润(万元): '))
if i <= 10:
    j = i * 0.1
elif i <= 20:
    j = (i -10 ) * 0.075 + 1
elif i <= 40:
    j = ( i - 20) * 0.05 + (0.075 * 10) + (0.1 * 10)
elif i <= 60:
    j = (i - 60) *0.03 + (0.05 * 20) + (0.075 * 10)+(0.1 * 10)
elif i <= 100:
    j = (i - 100) * 0.015 + (0.03 * 20) + (0.05 * 20) + (0.075 * 10)+(0.1 * 10)
elif i > 100:
    j = (i - 100) * 0.01 + (0.015 * 40)+ (0.03 * 20) + (0.05 * 20) + (0.075 * 10)+(0.1 * 10)
print('本月的奖金为:', j ,'万元')

苍月枫 发表于 2019-3-7 22:51:10

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


楼主的看着简洁,但是个人感觉针对题目来说,不像纯数学方法那样通俗易懂。但是对于开发来说,这种应该比我那种一堆if语句要好吧
页: 1 2 3 4 [5] 6 7
查看完整版本: Python:每日一题 2