Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(cities.py) Write a program that asks user for a city name, compares that value with the contents of two text files, and reports each match

image text in transcribed
image text in transcribed
(cities.py) Write a program that asks user for a city name, compares that value with the contents of two text files, and reports each match if any). Define a function to handle importing file data into a list. 2. Step 1: Define function Function Input Argument Processing Output Open file for reading. See textbook pages 322-3 (lines 5-11) Read each city name and store in list. See textbook pages 322-3 (lines 13-17) Handle IOError exception by printing an error A list populated with the city names for that state file21ist file name message and returning an empty list. Suggestion: Use try-except-else construct. Remember to close the file. Result of test (NH file name spelled wrong): Your VT list contains 123 elements. Code you can use to test function: mylist-file2list('vt municipalities.txt print ('Your VT list contains',len (mylist), elements. mylist-file2list ('nh munic.txt' print ('Your nh list contains' FILE ERROR: nh munic.txt cannot be found. Your NH 1ist contains 0 elements. len (mylist) elements. Step 2: Use main) for user interaction a) Populate two lists, one each with the contents of vt_municipalities.tsdt and nh municipalities.txt. To do this, call your file2list function. b) Use len function to be sure your lists are not empty. c) If either list is empty, do nothing. Otherwise, prompt the user for a city name and report the results as shown. Continuing prompting for additional city names (cities.py) Write a program that asks user for a city name, compares that value with the contents of two text files, and reports each match if any). Define a function to handle importing file data into a list. 2. Step 1: Define function Function Input Argument Processing Output Open file for reading. See textbook pages 322-3 (lines 5-11) Read each city name and store in list. See textbook pages 322-3 (lines 13-17) Handle IOError exception by printing an error A list populated with the city names for that state file21ist file name message and returning an empty list. Suggestion: Use try-except-else construct. Remember to close the file. Result of test (NH file name spelled wrong): Your VT list contains 123 elements. Code you can use to test function: mylist-file2list('vt municipalities.txt print ('Your VT list contains',len (mylist), elements. mylist-file2list ('nh munic.txt' print ('Your nh list contains' FILE ERROR: nh munic.txt cannot be found. Your NH 1ist contains 0 elements. len (mylist) elements. Step 2: Use main) for user interaction a) Populate two lists, one each with the contents of vt_municipalities.tsdt and nh municipalities.txt. To do this, call your file2list function. b) Use len function to be sure your lists are not empty. c) If either list is empty, do nothing. Otherwise, prompt the user for a city name and report the results as shown. Continuing prompting for additional city names

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intelligent Databases Technologies And Applications

Authors: Zongmin Ma

1st Edition

1599041219, 978-1599041216

More Books

Students also viewed these Databases questions

Question

7. General Mills

Answered: 1 week ago

Question

Why do HCMSs exist? Do they change over time?

Answered: 1 week ago