London 2012

london-2012

Learning Objectives


In this challenge we are going to investigate methods that can be used to:

  • Read and extract data from a text file,
  • Sort this data in ascending or descending order,
  • Display this sorted data on screen.

Context


We have a text file with the list of the 10 top countries at the London 2012 Olympic Games. (Countries which won the most gold medals). This data is not sorted and is organised as follows:

Name of Country;Number of Gold Medals;Number of Silver Medals;Number of Bronze Medals

You can download this text file:

TextFilecountries.txt

Step by Step


To achieve our goal of reading the text file, sorting its data and displaying it on the screen we will proceed in 5 steps:
5steps

Python Code



Your Challenge


Tweak this code to:

  • Sort this list in ascending order of gold medals
  • Sort this list in alphabetical (ascending) order of name of country
  • Sort this list in descending order of silver medals
  • Sort this list in descending order of bronze medals
  • Sort this list in descending order of total number of medals (Bronze + Silver + Gold medals)
Share Button
Posted in Computer Science, Python - Intermediate, Python Challenges Tagged with: , ,

Our Latest Book