2012-12-17 116 views
0

我正在解析一个文件,并且我想构建一个包含用户选择的名称和值的字典。因为我有许多名字我想展现给用户的名称,他将选择的年龄:Python中的字典错误

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 

我该如何修复它?

在此先感谢

+2

为什么你期望input()接受多于一个参数?可以使用字符串标注或字符串插值。 –

+0

@ user1833746顺便说一下,它是'concatenation':P – jackcogdill

+0

@ user1833746:很可能是因为print()* * *。 –

回答

1

更换input("choose the age of", param["name"], " :\n")

有了:input("choose the age of "+ param["name"]+ " :\n")

甚至:input("choose the age of %s:\n" % param["name"])

input()接受一个字符串,你想使用print用逗号输出,你不能做这个。将字符串连接成一个。

0

你想

input("choose the age of %s\n" % param["name"]) 

搜索字符串插值的文档。