python(⼗⼆)while循环填充字典
while语句怎么用pythoneg:创建⼀个调查程序,其中的循环每次执⾏时都提⽰输⼊被调查者的名字和回答。我们将收集的数据存储在⼀个字典中,以便将回答同被调查者关联起来
responses = {}
#设置⼀个标志,指出调查是否继续
polling_active = True
while polling_active:
#提⽰输⼊被调查者的名字和回答
name = input("\nWhat is your name?")
response = input("Which mountain would you like to climb someday?")
#将答案存储在字典中
responses[name] = response
#看看是否还有⼈要参与调查
repeat = input("Would you like to another person respond?(yes/no)")
if repeat == 'no':
polling_active = False
#调查结束,显⽰结果
print("\n--- Poll Results ---")
for name,response in responses.items():
print(name + " would like to climb "+ response + ".")

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。