This Python program analyzes a list of rivers, each with coverage percentage and length.
It filters rivers that cover more than half of the plateau and identifies the one with the greatest length.
# Sample data: river name, coverage (%), and length (km)
rivers = [
{"name": "River A", "coverage": 40, "length": 600},
{"name": "River B", "coverage": 55, "length": 720},
{"name": "River C", "coverage": 70, "length": 680},
{"name": "River D", "coverage": 30, "length": 500}
]
# Filter rivers that cover more than 50% of the plateau
filtered = [r for r in rivers if r["coverage"] > 50]
# Find the river with the longest length
longest = max(filtered, key=lambda r: r["length"])
# Display the result
print("Longest river covering the plateau:", longest["name"])
Longest river covering the plateau: River B
- The list rivers contains dictionaries with coverage and length data
- Rivers with coverage greater than 50% are selected using a list comprehension
- The max() function identifies the river with the highest length
- The name of the longest qualifying river is printed