Apr-14-2020, 04:49 PM
(This post was last modified: Apr-14-2020, 04:49 PM by deanhystad.)
The function, as written, finds the number of islands taller than the shortest island in the list. It also does this in a very inefficient way, but that doesn't really matter since the function does not do what it is supposed to do.
The function needs inputs for the list of elevations AND the sea level. This makes the function a useful tool.
"How many islands are lost if the sea level rises 10'" (or whatever unit)
print(len(elevations) - count_islands(elevations, 10))
Or you could make a chart of islands vs sea level. This creates a list of (sea level, island count) pairs:
points = [(sl, count_islands(sl) for sl in range(230)]
The function needs inputs for the list of elevations AND the sea level. This makes the function a useful tool.
def count_islands(elevations, sealevel): islands = 0 for elevation in elevations: if elevation >= sealevel: islands += 1 return islandsNow you can answer questions like:
"How many islands are lost if the sea level rises 10'" (or whatever unit)
print(len(elevations) - count_islands(elevations, 10))
Or you could make a chart of islands vs sea level. This creates a list of (sea level, island count) pairs:
points = [(sl, count_islands(sl) for sl in range(230)]