Answer to Question #267452 in Python for kavin

Question #267452

write a program in Python to store the name of five cities list create a function search name to search city using Linear search if the required name was and name it is not available the function should return -1

1
Expert's answer
2021-11-17T06:29:47-0500
cities = ['Moscow', 'New York', 'Ekaterinburg', 'Tokyo', 'Berlin']


def search_city(name):
    for city in cities:
        if city.lower() == name.lower():
            return True
    return -1
    
name = input()
print(search_city(name))

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS