Your challenge is to write a Python program that will read through the data from the US States.txt text file provided below in order to find out:
- The total population in the USA (by adding the population of each of the 51 states,
- The average population per state,
- The state which has the highest population,
- The state which has the lowest population,
- A list of all 51 states with their population as a percentage of the total US population.
The given text file is a CSV file (Comma Separated Values) with the following fields:
By completing this challenge you will learn how to read through and extract data from a CSV file. You may want to read this blog post about handling text files using Python first.
Complete the code
The code below read through the text file line by line using a for loop. For each line it extracts the data using the split() method.
Challenge #2: Compare State Population Game
Use this text file to create a Python game where the computer randomly displays two states on the screen (with their full name and their 2-letter code) and asks the user to guess which of the two states has the largest population. If the user guesses it right, they score one point otherwise they lose one point.
Solution...The solution for this challenge is available to full members!
Find out how to become a member:
➤ Members' Area