我想知道我如何能使一个精确匹配的数组搜索,如果城市没有找到它应该输出“不是一个城市在密歇根州。”
代码应该输出: 芝加哥 布鲁克林 沃特夫利特 顶点
citiesInMichigan = ["Acme", "Albion", "Detroit", "Watervliet", "Coloma", "Saginaw", "Richland", "Glenn", "Midland", "Brooklyn"]
# Get user input
inCity = input("Enter name of city: ")
# Write your test statement here to see if there is a match.
if inCity == citiesInMichigan:
print("City Found")
# If the city is found, print "City found."
# Otherwise, "Not a city in Michigan" message should be printed.
您可以使用in语句。你知道吗
注意in语句是完全匹配的。这意味着您可能需要对输入进行微调和小写/大写。你知道吗
相关问题 更多 >
编程相关推荐