鱼C论坛

 找回密码
 立即注册
查看: 1331|回复: 1

[已解决]str()

[复制链接]
发表于 2017-11-14 15:25:42 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
responses = []

# 设置一个标志,指出调查是否继续

polling_active = True

name = input("\nWhat's your name?")

response = input("If you could visit one place in the world.where would you go?")

# 将答案存储在字典里

responses[name] = response

# 看看食肉还有人要参与调查

repeat = input("Would you like ti let 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 + '.')



What's your name?weixinyi
If you could visit one place in the world.where would you go?xiangshan
Traceback (most recent call last):
  File "C:/Users/Administrator/AppData/Local/Programs/Python/Python36/ibj.py", line 13, in <module>
    responses[name] = response
TypeError: list indices must be integers or slices, not str

问题:这个问题是我配置环境问题吗?代码没有错误啊
最佳答案
2017-11-14 15:34:15
你要创建字典,请用
responses = {}
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2017-11-14 15:34:15 | 显示全部楼层    本楼为最佳答案   
你要创建字典,请用
responses = {}
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-4-19 22:50

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表