Question
Q#4 Write a program that reads the contents of file Cities.txt into a list. The program should ask the user to enter the names of
Q#4 Write a program that reads the contents of file Cities.txt into a list. The program should ask the user to enter the names of two cities. (Tip: Keep in mind that the city#1 entered by the user may not exist in the list. In this case, you must show that city#1 was not found). Then, in the list, replace all occurrences of city #1 with city #2. At the end, show the updated list of cities. Handle any exceptions that may be raised in the program.
Cities.txt
Boston New York Chicago Chicago Chicago Pittsburgh Philadelphia Philadelphia Boston Philadelphia Boston Boston Boston Chicago Boston Cincinnati Cleveland New York New York New York Washington Pittsburgh St. Louis New York New York Philadelphia Philadelphia St. Louis New York New York St. Louis Detroit New York New York New Yotk New York Cincinnati New York St. Louis New York St. Louis Detroit St. Louis New York Cleveland New York New York New York New York New York New York Brooklyn New York Milwaukee New York Los Angeles Pittsburgh New York New York Los Angeles St. Louis Los Angeles Baltimore St. Louis Detroit New York Baltimore Pittsburgh Oakland Oakland Oakland Cincinnati Cincinnati New York
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started