【发布时间】:2020-06-29 21:14:05
【问题描述】:
我想做的事:
询问用户他们想找到多少喜剧演员。
用户输入 5
然后在控制台中提示用户问题 1:“什么是喜剧演员号码 [1]” 他们输入名字,然后提示“什么是喜剧演员号码[2]”等等,直到输入喜剧演员号码 5...
最后,我想将这些输入收集到一个列表中以备后用。
到目前为止,代码已经到了:
Question = int(input("How Many Comedians Do You Want to Find?: "))
lst = list(range(1, Question + 1))
lst_of_input = []
while Question > 0 :
for i in range(len(lst)):
iterator = i
s = input("What is Comedian number {}?: ".format(*iterator))
if s == "Done":
break
lst_of_input.append(s)
print(lst_of_input)
有些元素是实验性的。为了停止 while 循环,我包括如果输入了 Done,则 while 循环将中断并返回输入的值。
我在运行时收到的错误是:
TypeError: format() argument after * must be an iterable, not int
【问题讨论】:
标签: python python-3.x list list-comprehension string.format