← Back to challenges

Rounding in Millions

PythonHardlanguage_fundamentalsloopsnumbersobjects

Instructions

Given a list of cities and populations, return a list where all populations are rounded to the nearest million.

Examples

millions_rounding([
  ["Nice", 942208],
  ["Abu Dhabi", 1482816],
  ["Naples", 2186853],
  ["Vatican City", 572]
])
[
  ["Nice", 1000000],
  ["Abu Dhabi", 1000000],
  ["Naples", 2000000],
  ["Vatican City", 0]
]

Notes

Round down to 0 if a population is below 500,000.

python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Valid Zip Code