Question: 1. Use the program citiesStart.py 2. Add the following city to the array initialized as citiesInMichigan[Dearborn a. Change the appropriate values to accommodate the array
1. Use the program citiesStart.py 2. Add the following city to the array initialized as citiesInMichigan[Dearborn
a. Change the appropriate values to accommodate the array size change b. Use a constant to test the while loop initialized in Declarations
3. Add an outer loop to test for XXX entered for city to end the program
4. Initialize a second array to hold the found values (append to the array found[] after each time FOUND_IT is set to Y
a. Then print out the array called found[] at the end of the program in a separate loop with an if statement to print Cities found first time through the loop
b. Hint: Use the len(found) to check the loop end.
5. The output should be like below using the following cities for input: Chicago Acme Brooklyn Dearborn Oklahoma City
# 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", "Detroit", "Watervliet", "Coloma", "Saginaw", "Richland", "Glenn", "Midland", "Brooklyn"] found_it="N" # Get user input inCity = input("Enter name of city: ")
# Write your test statement here to see if there is a match. found_it="N" sub=0 while sub<10: if inCity==citiesInMichigan[sub]: # If the city is found, print "City found." found_it="Y" #print("City found") sub=sub+1 if found_it=="Y": print("City found.") else: print("Not a city in Michigan.")
6. Part 2---Change the input and create a text file with these input cities(ChicagoAcmeBrooklynDearbornOklahoma City). So your input statements will change to open and read the input cities(cities.txt) (Same output) 7. But the output should have a Heading printed first that says Cities of Michigan from Input File
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
