An Introduction to Programming

Python for All

Chapter Thirteen — Test

Thanasis Troboukis  ·  All Chapters

Chapter Thirteen

Test your knowledge.

You should be able to do the following exercise in 15 minutes, up to 30 minutes.

The list below contains Greek city names and population figures mixed together. City names have inconsistent capitalisation and some have extra spaces. Population figures are a mix of int, float, and str. Write code that reads through the list once and produces two clean lists: clean_cities with every name normalised, and clean_populations with every figure as an int. Then calculate and print the total population of all cities, the average population per city, and the city with the smallest and the largest population.

Python · Your solution

Chapter Navigation

Move between chapters.

Loading Python environment — this may take a moment…