Question: This assignment has one script with two parts. All print output should include descriptions as shown in the example output below. Your script should contain

This assignment has one script with two parts.

All print output should include descriptions as shown in the example output below. Your script should contain a main function.

Part One Working with Files

Create a new file called ZenOfPython.txt and write the first two lines of the Zen of Python (see The Zen of Python) to the file. Close the file.

Reopen the file and append the 7th and the 17th lines. Then close the file.

Open the file again and read and print the entire contents of the file (there shouldn't be any blank lines between the text). Then close the file.

Sample Execution Results:

Beautiful is better than ugly. Explicit is better than implicit. Readability counts. If the implementation is hard to explain, it's a bad idea. 

Part Two CSV Files

For this exercise, you will need to download the file Cities.csv from Canvas and save it into the same directory as your Python script. To do this, login to Canvas, select CIS 41A, select Files, select Cities.csv, select Download, and save into the same directory with your unit G in-class Python script.

The file contains a list of cities, their state, and their population. The file starts with a header row of field names, which are City, State, Population.

You will need to save this data (but not the header data) into a dictionary. The dictionary key will be a tuple consisting of the name of the city and the name of the state. The dictionary value will be the population. The reason for this structure is that there are a number of duplicate city names within the file, but no duplicate city/state pairs.

Hint: When you create your reader object, you should use the DictReader from the csv module. Because the file contains a header row of field names, we dont have to explicitly define them when creating the reader object. However, you should use these field names instead of numerical indexes when working with the row data.

After reading the csv file, iterate through the dictionary and print the data.

Then, ask the user for a city and state, then print that citys population, if it exists. Test with Dublin, California.

Sample Execution Results:

Athens Georgia 115452 Athens Ohio 23832 Berlin Connecticut 19866 Berlin Wisconsin 5524 Dublin California 46036 Dublin Ohio 41751 and so on... Please enter a city: Dublin Please enter a state: California Dublin California has a population of 46036

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!