【发布时间】:2017-09-05 13:33:31
【问题描述】:
我是 python 和编码方面的新手,我真的不明白为什么我的程序不能正常工作。预期的效果是“名称想要去 [destinations]”,而我的代码没有区分不同的“{names : [destinations]}”对。
这是我的代码,感谢您的关注:)
response = {}
destinations = []
ptname = 'name pls.'
prompt = 'input some places in the world, input next to go to the next user'
active = True
unfinished = True
while active:
unfinished = True
name = input(ptname)
while unfinished:
destination = input(prompt)
if destination != 'next':
destinations.append(destination)
print(destination + ' has been added to your list.')
response[name] = destinations
elif destination == 'next':
unfinished = False
go_on = input('wish to continue? y/n')
if go_on == 'n':
active = False
print(response)
for name, destinations in response.items():
print(name + ' wants to go to ')
for destination in destinations:
print(destination)
【问题讨论】:
标签: python python-3.x dictionary