116k views
2 votes
Write a program that uses a list which contains valid names for 10 cities in Michigan. You ask the user to enter a city name; your program then searches the list for that city name. If it is not found, the program should print a message that informs the user the city name is not found in the list of valid cities in Michigan. You need to write code to examine all the items in the list and test for a match. You also need to determine if you should print the "Not a city in Michigan." message.

User Cicolus
by
4.8k points

1 Answer

1 vote

Answer:

michigan = ['DETROIT',

'GRAND RAPIDS',

'WARREN',

'STERLING HEIGHTS',

'LANSING',

'ANN ARBOR',

'FLINT',

'DEARBORN',

'LIVONIA',

'WESTLAND'

]

city = input('Enter a city in Michigan: ').upper()

if city in michigan:

print('{} is a city in Michigan'.format(city))

else:

print('{} is Not a city in Michigan'.format(city))

Step-by-step explanation:

The programming language used is python.

A list containing, 10 cities in Michigan is created.

The program then asks the user to enter a city, and it converts the user's input to uppercase, to ensure that there is uniformity.

The IF and ELSE statements are used to check if the city is in Michigan, and to print a result to the screen.

Write a program that uses a list which contains valid names for 10 cities in Michigan-example-1
User Khb
by
5.5k points