鱼C论坛

 找回密码
 立即注册
查看: 1207|回复: 2

[已解决]麻烦大神帮忙看下哪里出现了错误,运行不起来

[复制链接]
发表于 2020-1-10 13:01:41 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
  1. def calcutre_profit(I):
  2.     #各种金额的分界值
  3.     arr = [1000000,600000,400000,200000,100000,0]
  4.     #分界值所对应的奖金比例值
  5.     rat = [0.01,0.015,0.03,0.05,0.075,0.1]
  6.     r = 0                      #这个是将近的初始值
  7.     for idx in range(0,6):              #有6个分界值,需要循环6次
  8.         if I > arr[idx]:
  9.             r = r * (I - arr[idx]) * rat[idx]
  10.             I = arr[idx]
  11.         return r


  12. I = int(input('净利润:'))
  13. profit = calcute_profit(I)
  14. print('利润为arr元时,应发奖金总数为rat元' ,(I, profit))
复制代码
最佳答案
2020-1-10 13:17:34
本帖最后由 jackz007 于 2020-1-10 14:06 编辑

        试试这个代码呢?
  1. def calculate_profit(I):
  2.     arr = [1000000 , 600000 , 400000 , 200000 , 100000 , 0]
  3.     rat = [0.01 , 0.015 , 0.03 , 0.05 , 0.075 , 0.1]
  4.     if I >= arr[0]:
  5.         idx = 0
  6.     else:
  7.         for idx in range(1 , len(arr)):
  8.             if arr[idx] <= I < arr[idx - 1] :
  9.                 break
  10.     return rat[idx] * I
  11. I = int(input('净利润:'))
  12. profit = calculate_profit(I)
  13. print('利润为 %d 元时,应发奖金总数为 %d 元' % (I , profit))
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2020-1-10 13:17:34 | 显示全部楼层    本楼为最佳答案   
本帖最后由 jackz007 于 2020-1-10 14:06 编辑

        试试这个代码呢?
  1. def calculate_profit(I):
  2.     arr = [1000000 , 600000 , 400000 , 200000 , 100000 , 0]
  3.     rat = [0.01 , 0.015 , 0.03 , 0.05 , 0.075 , 0.1]
  4.     if I >= arr[0]:
  5.         idx = 0
  6.     else:
  7.         for idx in range(1 , len(arr)):
  8.             if arr[idx] <= I < arr[idx - 1] :
  9.                 break
  10.     return rat[idx] * I
  11. I = int(input('净利润:'))
  12. profit = calculate_profit(I)
  13. print('利润为 %d 元时,应发奖金总数为 %d 元' % (I , profit))
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-1-10 14:12:14 | 显示全部楼层
jackz007 发表于 2020-1-10 13:17
试试这个代码呢?

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

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-5-26 13:37

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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