#!usr/bin/python
listofnames = []
names = input("Pls enter how many of names:")
x = 1
for x in range(0, names):
inname = input("Enter the name " + str(x))
listofnames.append(inname)
print listofnames
inname = input("Enter the name " + str(x))
文件 「」,第1行,在 NameError:名稱 '約翰' 沒有定義
請注意,您可以使用列表理解來做到這一點;代碼模式'var = []; for ...:var.append(...)'是線索。 'listofnames = [raw_input(「Name%d?」%x)for x in range(int(raw_input(「How many names?」)))]'。 – katrielalex 2010-08-16 09:10:57