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.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

please in python coing

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.
Transcribed Image Text: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 don't 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 city's 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
Transcribed Image Text: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 don't 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 city's 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
Expert Solution
steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Knowledge Booster
File Input and Output Operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education