python中的字典出错
我正在解析一个文件,我想构建一个包含用户选择的名称和值的字典。由于我有许多姓名,我想向用户显示他将选择年龄的姓名:python中的字典出错,python,input,dictionary,for-loop,Python,Input,Dictionary,For Loop,我正在解析一个文件,我想构建一个包含用户选择的名称和值的字典。由于我有许多姓名,我想向用户显示他将选择年龄的姓名: Choose the age of Jack choose the age of Kate ... 以下是我编写的代码: list_param = {} for param in o["persons"]: list_param.update({param["name"]: input("choose the age of", param["name"], " :\n" )
Choose the age of Jack
choose the age of Kate
...
以下是我编写的代码:
list_param = {}
for param in o["persons"]:
list_param.update({param["name"]: input("choose the age of", param["name"], " :\n" )})
我得到这个错误:
TypeError: [raw_]input expected at most 1 arguments, got 3
我怎样才能修好它
提前感谢替换输入(“选择年龄”,参数[“名称”],“:\n”)
使用:input(“选择“+param[“name”]+”:\n”的年龄”)
甚至:input(“选择%s的年龄:\n”%param[“name”])
input()
接受一个字符串,您正在考虑使用带有逗号的print
输出,您不能这样做。将字符串连接为一个。您需要
input("choose the age of %s\n" % param["name"])
在文档中搜索字符串插值。为什么希望input()接受多个参数?使用字符串连接或字符串插值。@user1833746顺便说一句,它是
连接
:P@user1833746:很可能是因为print()。