鱼C论坛

 找回密码
 立即注册
楼主: 新手·ing

[技术交流] Python:每日一题 2

  [复制链接]
发表于 2018-8-21 17:37:20 | 显示全部楼层
  1. x= int(input('please input your profit number (the unit is ten thousand):' ))
  2. y=0
  3. if x <= 10 :
  4.         y = x * 0.1
  5. elif 10 <x <= 20 :
  6.         y= (x-10)*0.075+10*0.1
  7. elif 20<x<=40:
  8.         y=(x-20)*0.05+(x-10)*0.075+10*0.1
  9. elif 40<x<=60:
  10.         y=(x-40)*0.03+(x-20)*0.05+(x-10)*0.075+10*0.1
  11. elif 60<x<=100:
  12.         y=(x-60)*0.015+(x-40)*0.03+(x-20)*0.05+(x-10)*0.075+10*0.1
  13. elif 100 < x :
  14.         y=(x-100)*0.01+(x-60)*0.015+(x-40)*0.03+(x-20)*0.05+(x-10)*0.075+10*0.1

  15. print(y)
复制代码



上传代码格式。。嘻嘻。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-8-23 10:18:05 | 显示全部楼层
本帖最后由 acgods 于 2018-8-23 10:22 编辑
  1. MonthProfit = int(input("请输入当月的利润:"))
  2. prize = 0
  3. def prize(MonthProfit):
  4.     if MonthProfit <= 100000:
  5.         prize = MonthProfit * 0.1
  6.     elif 100000 < MonthProfit <= 200000:
  7.         prize = 100000 * 0.1 + (MonthProfit - 100000)* 0.075
  8.     elif 200000 < MonthProfit <= 400000:
  9.         prize = 100000 * 0.1 + 100000 * 0.075 + (MonthProfit - 200000) * 0.05
  10.     elif 400000 < MonthProfit <= 600000:
  11.         prize = 100000 * 0.1 + 100000 * 0.075 + 200000 * 0.05 + (MonthProfit -400000) * 0.03
  12.     elif 600000 < MonthProfit <= 1000000:
  13.         prize = 100000 * 0.1 + 100000 * 0.075 + 200000 * 0.05 + 200000 * 0.03 + (MonthProfit - 600000) * 0.015
  14.     else:
  15.         prize = 100000 * 0.1 + 100000 * 0.075 + 200000 * 0.05 + 200000 * 0.03 + 400000 * 0.015 + (MonthProfit - 1000000) * 0.01
  16.     return prize

  17. print("本月的奖金为:" + str(prize(MonthProfit)))
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-8-30 18:55:18 | 显示全部楼层

比我想的简洁,楼主大佬
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-9-3 13:51:16 | 显示全部楼层
  1. def pr(proft):
  2.     #利润(I)低于或等于10万元时,奖金可提10%
  3.     bonus = proft + proft*0.1

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

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

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

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

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

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

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

  18.     if proft == '.w':
  19.         break
  20.    
  21.     proft = int(proft)
  22.    
  23.     bonus,bonus2,bonus3,bonus4,bonus5,bonus6 = pr(proft)
  24.    
  25.     if (proft > 10E+5):
  26.         print(bonus6)

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

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

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

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

  35.     else:
  36.         print(bonus)
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 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)
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-9-18 11:14:49 | 显示全部楼层
jj = 0
fl = [100, 60, 40, 20, 10, 0]
ll = [0.01, 0.015, 0.03, 0.05, 0.075, 0.1]
lr = int(input("请输入利润:"))
for i in range(6):
    if lr > fl[i]:
        jj += (lr - fl[i]) * ll[i]
        print(jj)
        lr = fl[i]

print(jj)
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-10-6 23:01:02 | 显示全部楼层
bonus_list={100000:[0.075,10000],200000:[0.05,17500],400000:[0.03,27500],600000:[0.015,33500],1000000:[0.01,3.95]}
def money(profit,bonus_list=bonus_list):
    profit_section = [i for i in bonus_list.keys() if profit >i]
    if profit_section ==[]:
        return profit*0.1
    else:
        temp =[profit_section[0]]+ bonus_list[profit_section[0]]
       
        return (profit-temp[0])*temp[1]+temp[2]
try:
    i=int(input("请输入利润"))
    print(money(i)
except:print("请输入正确的利润")
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 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)
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-10-21 20:17:07 | 显示全部楼层

就服你!
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 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)
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 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))

看了楼主的,再看自己的,太复杂了..
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-12-19 14:11:41 | 显示全部楼层
本帖最后由 sunrise085 于 2018-12-19 14:12 编辑

对于多次if...else...判断就不写了。我写了三个版本,第一个版本中有三个列表,分别是利润数轴列表、奖金比例列表、分段奖金列表,程序先判断利润在哪个区间,然后去查表计算总奖金。
  1. mylist1 = [1000000,600000,400000,200000,100000,0]
  2. mylist2 = [0.01,0.015,0.03,0.05,0.075,0.1]
  3. mylist3 = [39500,33500,27500,17500,10000,0]
  4. I = input('请输入当前月利润I:')
  5. I = int(I)
  6. for i in range(0,len(mylist1)):
  7.         if I > mylist1[i]:
  8.                 break
  9. fee = (I-mylist1[i]) * mylist2[i]+mylist3[i]
  10. print ('奖金总数:',fee)
复制代码

第二个版本中有两个列表,分别是利润数轴列表、奖金比例列表,直接循环计算总奖金。
  1. mylist1 = [1000000,600000,400000,200000,100000,0]
  2. mylist2 = [0.01,0.015,0.03,0.05,0.075,0.1]
  3. I = 150000#input('请输入当前月利润I:')
  4. temp = int(I)
  5. fee = 0
  6. for i in range(0,len(mylist1)):
  7.         if temp > mylist1[i]:
  8.                 fee += (temp-mylist1[i]) * mylist2[i]
  9.                 temp = mylist1[i]
  10. print ('奖金总数:',fee)
复制代码

第三个版本是将第二个版本进行改进,利用函数写了一个递归,通过递归函数计算总奖金。
  1. def fee(I):
  2.         mylist1 = [1000000,600000,400000,200000,100000,0]
  3.         mylist2 = [0.01,0.015,0.03,0.05,0.075,0.1]
  4.         for i in range(0,len(mylist1)):
  5.                 if I > mylist1[i]:
  6.                         fees = (I - mylist1[i]) * mylist2[i] + fee(mylist1[i])
  7.                         break
  8.         if I == 0:
  9.                 return 0
  10.         return fees

  11. I = input('请输入当前月利润I:')
  12. temp = int(I)
  13. print ('奖金总数:',fee(I))
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-12-31 13:46:29 | 显示全部楼层
  1. def do1(a):
  2.     if a <= 100000L:
  3.         return a * 0.1
  4.     elif 100000L < a <= 200000L:
  5.         return (a - 100000L) * 0.075 + do1(100000L)
  6.     elif 200000L < a <= 400000L:
  7.         return (a - 200000L) * 0.05 + do1(200000L)
  8.     elif 400000L < a <= 600000L:
  9.         return (a - 400000L) * 0.03 + do1(400000L)
  10.     elif 600000L < a <= 1000000L:
  11.         return (a - 600000L) * 0.015 + do1(600000L)
  12.     else:
  13.         return (a - 1000000L) * 0.01 + do1(1000000L)


  14. if __name__ == '__main__':
  15.     a = input("请输入利润:")
  16.     print(do1(long(a)))
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2019-2-6 21:14:55 | 显示全部楼层
  1. i = int(input('请输入您的利润:'))

  2. bouns = 0


  3. if i > 1e6:
  4.     bouns += (i - 1e6) * 0.010
  5.     i = 1e6
  6. if i > 6e5:
  7.     bouns += (i - 6e5) * 0.015
  8.     i = 6e5
  9. if i > 4e5:
  10.     bouns += (i - 4e5) * 0.030
  11.     i = 4e5
  12. if i > 2e5:
  13.     bouns += (i - 2e5) * 0.050
  14.     i = 2e5
  15. if i > 1e5:
  16.     bouns += (i - 1e5) * 0.075
  17.     i = 1e5
  18. if i <= 1e5:
  19.     bouns += i * 0.100

  20. print(bouns)
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 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)

為什麼一直語法錯誤
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 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('输入有误')#---还缺少异常捕抓
   
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 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)
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 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)
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2019-3-7 22:47:38 | 显示全部楼层
  1. j = 0
  2. i = int(input('请输入该月利润(万元): '))
  3. if i <= 10:
  4.     j = i * 0.1
  5. elif i <= 20:
  6.     j = (i -10 ) * 0.075 + 1
  7. elif i <= 40:
  8.     j = ( i - 20) * 0.05 + (0.075 * 10) + (0.1 * 10)
  9. elif i <= 60:
  10.     j = (i - 60) *  0.03 + (0.05 * 20) + (0.075 * 10)+(0.1 * 10)
  11. elif i <= 100:
  12.     j = (i - 100) * 0.015 + (0.03 * 20) + (0.05 * 20) + (0.075 * 10)+(0.1 * 10)
  13. elif i > 100:
  14.     j = (i - 100) * 0.01 + (0.015 * 40)  + (0.03 * 20) + (0.05 * 20) + (0.075 * 10)+(0.1 * 10)
  15. print('本月的奖金为:', j ,'万元')
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2019-3-7 22:51:10 | 显示全部楼层

楼主的看着简洁,但是个人感觉针对题目来说,不像纯数学方法那样通俗易懂。但是对于开发来说,这种应该比我那种一堆if语句要好吧
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-4-27 21:53

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表