Python入门习题大全——索引
编写一个程序,调查用户梦想的度假胜地。使用类似于"Ifyou could visit one place in the word, where would you go?"的提示, 并编写一个打印调查结果的代码块。
# 梦想的度假胜地
places = {}
prompt = "What is your name? \n"
prompt += "Enter 'quit' when you finished. \n"
message = "If you could visit one place in the world, where would you go? \n"
active = True
while active:
name = input(prompt)
if name == 'quit':
break
place = input(message)
places[name] = place
for name, place in places.items():
print(name + " wants to go to " + place + ".")
输出为:
(依次输入 ling,a,huihe,b,quit)
What is your name?
Enter 'quit' when you finished.
ling
If you could visit one place in the world, where would you go?
a
What is your name?
Enter 'quit' when you finished.
huihe
If you could visit one place in the world, where would you go?
b
What is your name?
Enter 'quit' when you finished.
quit
ling wants to go to a.
huihe wants to go to b.
Process finished with exit code 0