/Python-Training_4

Created while learning Python at Cornell Tech

Primary LanguagePython

Programming Assignment 4

Fundamentals of Modern Software
Fall 2019
Due 11:59 PM, Wednesday, October 2

Introduction

This assignment will give you practice writing programs to work with large datasets in a variety of file formats.

REMINDERS

  1. When you are done, be sure to submit your work.
  2. You must adhere to the collaboration policy in the syllabus. You MAY NOT copy the code of someone else in the class or allow someone else to copy your code.
  3. Be sure to test your programs thoroughly. We will.

babynames.py

The Social Security Administration maintains an annual list of all new baby names. The lists are available for download from https://www.ssa.gov/oact/babynames/limits.html; we have given you the national year-by-year lists in the babies subdirectory. The file NationalReadMe.pdf in that directory documents the format used by the SSA. Write a program that identifies the 100 most commonly used male and female baby names from 1880 through 2016 (i.e, the names given to the most total babies).

Your program should save the names to an output JSON file, popularnames.json, which lists the top 100 names for each gender in descending order of popularity. The file should be formatted to match the following (with different names and counts, of course):

{"male": [{"name": "mario", "count": 500000}, {"name": "luigi", "count": 300000}, {"name": "wario", "count": 1}], "female": [ {"name": "peach", "count": 400000}, {"name": "toadette", "count": 250000}]

To open a file in the babies subdirectory, add babies/ to the start of the filename, e.g. open(babies/yob1932.txt).

flights.py

We have given you a dataset of airports around the world in the file airports.json. Write a program which takes as a command-line argument the IATA code for an airport (e.g. EWR for Newark Liberty International) and prints out a list of airports one can connect to from that airport, sorted in order of distance from nearest to farthest.

$ python flights.py ITH
EWR Newark Liberty Intl 276km
PHL Philadelphia Intl 308km
DTW Detroit Metro Wayne Co 568km

To compute distances from one point to another on the surface of the Earth, you can use the geopy Python package. To compute the distance from a point with latitude lat1 and longitude long1 to a point with latitude lat2 and longitude long2, first $ from geopy import distance and then use the expression distance.distance([lat1,long1],[lat2,long2]).km. It takes two arguments, each of which is a list with two elements (the latitude and longitude of a point, measured in degrees, just as in airports.json) and returns a distance measured in kilometers.

(We have installed geopy in the Codio environment used for the assignment. If you ever need to use it in a different Codio environment, run the command $ pip install geopy from the command line. You should only need to do this once.)