# -*- coding: utf-8 -*-
states = [
'oregon': 'or', 运行时老是提示,冒号错误,是在英文半角下写的,但是还是出错,求解
'florida':'fl',
'california':'ca',
'new york':'ny'
]
cities = [
'ca':'sanfrancisco'
'mi':'detroit'
'fl':'jackonvile'
]
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 abbreviation is :',states['michigan']
print 'florida 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.item():
print "%s is abbreviated %s" %(state,abbrev)
print '-' * 10
for state,abbrev in states.items():
print "%s state is abbreviated %s and has city %s" %(state,abbrev,cities[abbrev])
print '-' * 10
state = states.get('texas',none)
if not state:
print "sorry ,no texas"
city = cities.get('tx','does not exist')
print "the city for the state 'tx' is :%s"%city
报错提示# -*- coding: utf-8 -*-
states = [
'oregon': 'or',
'florida':'fl',
'california':'ca',
'new york':'ny'
]
cities = [
'ca':'sanfrancisco'
'mi':'detroit'
'fl':'jackonvile'
]
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 abbreviation is :',states['michigan']
print 'florida 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.item():
print "%s is abbreviated %s" %(state,abbrev)
print '-' * 10
for state,abbrev in states.items():
print "%s state is abbreviated %s and has city %s" %(state,abbrev,cities[abbrev])
print '-' * 10
state = states.get('texas',none)
if not state:
print "sorry ,no texas"
city = cities.get('tx','does not exist')
print "the city for the state 'tx' is :%s"%city