#!/usr/bin/env python # coding: utf-8 # # Programming with Python # #### Stefan Güttel, [guettel.com](http://guettel.com) # # ## Lab classes: Files # Download the file [`Met_Office_2011_Air_Data.csv`](http://personalpages.manchester.ac.uk/staff/stefan.guettel/py/Met_Office_2011_Air_Data.csv) from [data.gov.uk](http://data.gov.uk/dataset/flight-data-2011/resource/e1be1a0a-565a-40cd-a8a7-e0bdf4f50dcc). # **Problem 1.** Write a program that reads the file `Met_Office_2011_Air_Data.csv` and prints: # # * Total cost for all the flights, # # * Total cost per each air carrier, sorted by that cost (i.e., the last carrier will be the one with whom the spending was biggest). # **Problem 2.** Write a program that inputs a journey finishing point and then reads the file `Met_Office_2011_Air_Data.csv` and prints total and average cost for all the journeys with that finishing point. The matching has to be case insensitive. # **Problem 3.** Write a program that reads the file `Met_Office_2011_Air_Data.csv` and in the directory `output` creates the files `single.csv` and `return.csv`, containing only the data for single and return flights, respectively. It has to copy all the data except the "Ticket Single or Return" column and both files have to be proper CSV files (with headers, and a comma as the column separator). # # Use the function [`os.path.exists`](https://docs.python.org/3/library/os.path.html#os.path.exists) to check if the output directory exists, the function [`os.mkdir`](https://docs.python.org/3/library/os.html#os.mkdir) to create it, and the function [`os.path.join`](https://docs.python.org/3/library/os.path.html#os.path.join) to join the directory name with filenames to create the output files' path names. # **Problem 4.** How many public toilets are there in each of the Australian towns, and how many of them are there in each of the Australian states? Of those towns that have a public toilet, which ones have the longest name and which one has the most toilets (and how many)? # # **Hint:** Write a program that will answer these questions by analyzing the CSV file that can be obtained [here](https://data.gov.au/dataset/national-public-toilet-map) (scroll down to `Latest CSV Export` and choose `Explore`, `Go to resource`).