Question: I need to take this code and change the input and create a text file with the input cities(Chicago, Acme, Brooklyn, Dearborn, Oklahoma City) so
I need to take this code and change the input and create a text file with the input cities(Chicago, Acme, Brooklyn, Dearborn, Oklahoma City) so that the input statements open and read the input cities(cities.txt). It needs to output the results of "city found" or "not a city in michigan" . The output should have a heading printed first that says "cities of Michigan from input file"
# MichiganCities.py - This program prints a message for invalid cities in Michigan. # Input: Interactive # Output: Error message or nothing
# Initialized list of cities citiesInMichigan = ["Acme", "Albion", "Dearborn", "Detroit", "Watervliet", "Coloma", "Saginaw", "Richland", "Glenn", "Midland", "Brooklyn"]
# Constant to test while loop NO_OF_TRIES = 5
# Initialize second array to hold values found = []
# Initialize foundIt to N found_it = "N"
# Get user input inCity = input("Enter name of city or XXX to end: ") counter = 0
# Write your test statement here to see if there is a match. while inCity != "XXX": found_it="N" while counter < 11: if inCity==citiesInMichigan[counter]: found_it="Y" found.append(citiesInMichigan[counter]) counter = counter + 1 if found_it == "N": print("Not a city in Michigan.") counter = 0 inCity = input("Enter name of city or XXX to end: ") print("The cities found are: ", found)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
