Проблема с функцией - PullRequest
1 голос

Пользователь вводит килограммы (например, 1800), которые необходимо преобразовать в кубические c метры, и функция должна вернуть результат.

Вот мой код:

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: максимальная глубина рекурсии превышена при сравнении

Как я могу исправить эту проблему?

1 Ответ

1 голос
/ 25 мая 2020

Вы пытаетесь вот так:

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
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...