我正在创建一种数据库,使用从用户读取的列表。当用户进入时,finish
我希望 while 循环停止。但是,由于某种原因,我需要输入finish
TWICE 才能打破循环。
此外,返回后列表为空。
def readNames():
nameList = []
count = 0
while count != -1: #infinite loop
addList = raw_input("Please enter a name: ")
if addList == 'finish':
return nameList
break
nameList.append(addList)
print nameList
我正在调用它并检查它是否适用
readNames()
print readNames()
另外,这是输出
Please enter a name: Dave
['Dave']
Please enter a name: Gavin
['Dave', 'Gavin']
Please enter a name: Paul
['Dave', 'Gavin', 'Paul']
Please enter a name: Test1
['Dave', 'Gavin', 'Paul', 'Test1']
Please enter a name: finish
Please enter a name: finish
[]
>>>