首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >不可排序的类型: NoneType() < NoneType()

不可排序的类型: NoneType() < NoneType()
EN

Stack Overflow用户
提问于 2019-04-14 14:08:21
回答 1查看 522关注 0票数 0

每当我在cheapest_shipping函数中输入一个大于10的值时,它就会给出一个不可排序的类型错误。

我尝试过将单独的变量传递给函数来计算成本。我还尝试了不同的比较运算符。

代码语言:javascript
运行
复制
cost = 0
pgs = 125

def gsp(weight):
  if weight == 0:
cost = 20
return cost
  elif weight <= 2:
cost = (1.5 * weight + 20)
return cost 
  elif weight > 2 and weight <= 6:
cost = (3 * weight + 20)
return cost
  elif weight > 6 and weight <= 10:
cost = (4 * weight + 20)
return cost
  elif weight > 10:
cost = (4.75 * weight + 20)

def dsp(weight):
  if weight == 0:
cost = 0
return cost
  elif weight <= 2:
cost = (4.5 * weight)
return cost 
  elif weight > 2 and weight <= 6:
cost = (9 * weight)
return cost
  elif weight > 6 and weight <= 10:
cost = (12 * weight)
return cost
  elif weight > 10:
cost = (14.25 * weight)

def cheapest_shipping(weight):
  if gsp(weight) < dsp(weight) and gsp(weight) < pgs:
return "Ground shipping is the cheapest option at $" + str(gsp(weight))
  elif dsp(weight) < gsp(weight) and dsp(weight) < pgs:
return "Drone shipping is the cheapest option at $" + str(dsp(weight))

print (cheapest_shipping(11))

该函数使用我的地面运输价格函数和无人机运输价格函数,以及溢价地面运输的成本,并采用权重输入,并应返回最便宜的运输选项。它在输入超过10之前一直工作。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-04-14 14:17:56

最后一条elif语句中缺少return cost。这可能就是你想要的

代码语言:javascript
运行
复制
cost = 0
pgs = 125


def gsp(weight):
    if weight == 0:
        cost = 20
        return cost
    elif weight <= 2:
        cost = (1.5 * weight + 20)
        return cost
    elif weight > 2 and weight <= 6:
        cost = (3 * weight + 20)
        return cost
    elif weight > 6 and weight <= 10:
        cost = (4 * weight + 20)
        return cost
    elif weight > 10:
        cost = (4.75 * weight + 20)
        return cost


def dsp(weight):
    if weight == 0:
        cost = 0
        return cost
    elif weight <= 2:
        cost = (4.5 * weight)
        return cost
    elif 2 < weight <= 6:
        cost = (9 * weight)
        return cost
    elif 6 < weight <= 10:
        cost = (12 * weight)
        return cost
    elif weight > 10:
        cost = (14.25 * weight)
        return cost


def cheapest_shipping(weight):
    if gsp(weight) < dsp(weight) and gsp(weight) < pgs:
        return "Ground shipping is the cheapest option at $" + str(gsp(weight))
    elif dsp(weight) < gsp(weight) and dsp(weight) < pgs:
        return "Drone shipping is the cheapest option at $" + str(dsp(weight))


print (cheapest_shipping(11))
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55672434

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档