I think you think too complicated.
Given is
Then you calculate the volume:
Then you return the minimum of
The test with your provided data:
Solving the problem with simple math is simpler.
By the way, your test code is wrong.
But the cause why you should always avoid
Given is
max_volume
, max_weight
and density
.Then you calculate the volume:
volume = max_weight / density
Then you return the minimum of
max_volume
and volume
.The test with your provided data:
Output:>>> calculate_possible_volume(1800)
14.555
>>> calculate_possible_volume(380)
67.5
The if, elif, else and for-loop is misleading.Solving the problem with simple math is simpler.
By the way, your test code is wrong.
def test_volume_per_container(): """Test the volume_per_container function.""" # Test for gravel at 1800 kg per cubic metre assert volume_per_container(1800) == 14.555 # Test for wood chips at 380 kg per cubic metre assert volume_per_container(380) == 67.5 print ("tests passed")Should be:
from math import isclose def test_volume_per_container(): """Test the volume_per_container function.""" # Test for gravel at 1800 kg per cubic metre assert isclose(volume_per_container(1800), 14.555) # Test for wood chips at 380 kg per cubic metre assert isclose(volume_per_container(380), 67.5) print ("tests passed")Both testes, if you have the right function name, passing.
But the cause why you should always avoid
float == float
is 0.30000000000000004.com. Tell this your tutor. He should know this.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
All humans together. We don't need politicians!