Question: Need help on question 2 using Python language, please.. I also include the q1 here, because q1 and q2 are using the same file. 1.
Need help on question 2 using Python language, please.. I also include the q1 here, because q1 and q2 are using the same file.
1. The file world-cities-populations.csv
is a comma-separated file that lists cities, populations and country for a large number of cities around the world. Write a program that takes as input this file. Load the entries into a dictionary where the key is the city name as it appears in the file, and the value is a tuple containing the population and country. Submit your source code as well as a session record of your program running and returning populations for any three cities.
#mycode
wcities = open("world-cities-population.csv", "r", encoding="mac_roman") thisdict = {}
for currentline in wcities: splitline = currentline.split(',') thisdict[splitline[4]] = (splitline[9], splitline[0]) for key, value in sorted(thisdict.items()): print(key, value)
2. Modify the program above to add a check to verify that the population field is a number. You do this by trying to convert the number to an integer, and surrounding that code with a try-except block. (I believe the population field is in letter J, which is the value)
Below is the screenshot of the file. Note: if there's a way to attach csv file here please let me know. Thank you.

Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
