我在Python中运行关于字典的练习,当我运行代码时它返回一个我无法调试的错误。我不知道我是否在字典中使用了错误的运算符,因为[]也在列表中使用
states = [
'Oregon''OR',
'Florida''FL',
'California' 'CA',
'New York''NY',
'Michigan' 'MI'
]
cities = [
'CA' 'San Francisco',
'MI' 'Detroit',
'FL' 'Jacksonville'
]
cities['NY'] = 'New York'
cities['OR'] = 'Portland'
print '_' * 10
print "NY State has: ", + cities['NY']
print "OR State has: ", + cities['OR']
print '_' * 10
print "Michigan's abbreviation is: " + states['Michigan']
print "Florida's abbreviation is: " + states['Florida']
print '_' * 10
print "Michigan has: ", cities[states['Michigan']]
print "Florida has: ", cities[states['Florida']]
print '_' * 10
for state, abbrev in states.items():
print "%s is abbreviated %s" % (state, abbrev)
print '_' * 10
for abberv, city in cities.items():
print "%s has the city %s" % (abbrev, city)
print '_' * 10
for state, abbrev in states.items():
print "%s state is abbreviated %s and has city %s" %(state, abbrev, cities[abbrev])
print '_' * 10
我收到了这条新消息
答案 0 :(得分:0)
请不要发布代码截图...
第35行缺少+
,但由于您只发布了一张图片,因此我不会为您输入正确的行。
答案 1 :(得分:0)
你需要添加+来连接字符串。
print"关于密歇根" +陈述[' michigan']
或
print"关于密歇根州的事情,#[;#michigan']