首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >发出一个函数

发出一个函数
EN

Stack Overflow用户
提问于 2020-05-25 15:13:29
回答 1查看 185关注 0票数 1

用户输入KGs (例如1800),该KGs应该转换为立方米,并且函数应该返回结果。

这是我的密码:

代码语言:javascript
复制
def volume_per_container(kg_cargo_per_cubic_metre):
    """Given the kg of cargo per cubic metre, calculate how many cubic metres
    of cargo can be stored in a single container."""
    max_volume_cubic_metres = 65.7
    max_net_load = 26199

    cubic_metre = kg_cargo_per_cubic_metre / max_net_load
    if cubic_metre >= 65.7:
        return volume_per_container (kg_cargo_per_cubic_metre) == max_volume_cubic_metres
    else:
        return volume_per_container (kg_cargo_per_cubic_metre) == cubic_metre

我知道这个错误:

RecursionError:比较超过最大递归深度

我怎样才能解决这个问题?

EN

回答 1

Stack Overflow用户

发布于 2020-05-25 15:28:24

你想这样做吗?

代码语言:javascript
复制
def volume_per_container(kg_cargo_per_cubic_metre):
    """Given the kg of cargo per cubic metre, calculate how many cubic metres
    of cargo can be stored in a single container."""
    max_volume_cubic_metres = 65.7
    max_net_load = 26199

    cubic_metre = kg_cargo_per_cubic_metre / max_net_load
    if cubic_metre >= max_volume_cubic_metres:
     return cubic_metre - max_volume_cubic_metres
    else:
     print("this much left to fill")
     return max_volume_cubic_metres - cubic_metre
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62005403

复制
相关文章

相似问题

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