你的代码没有实现要求的功能,我用python 3.x写了一个代码,实测可行,另外我修改成一版python 2.x的代码,没有办法测试。def plane_ride_cost(city):
if city == 'Charlotte':
return 183
elif city == 'Tampa':
return 220
elif city == 'Pittsburgh':
return 222
elif city == 'Los Angeles':
return 475
else:
return None
# Charlotte,Tampa,Pittsburgh,Los Angeles
citys = raw_input('Please input the citys split by comma:')
citys = citys.split(',')
for city in citys:
cost = plane_ride_cost(city)
print city, ':', cost
下面用python 3.x的测试结果: