使用Python 3.4.3
让我们说我创造了三个功能:
def choosing(mylist=[]):
print("We will have to make a list of choices")
appending(mylist)
done = False
while(done == "False"):
confirm = input("Is your list complete?[Y/N]")
if(confirm == "Y"):
print("Yaay! Choices creation complete."
"{} choices have been added successfully".format(len(mylist)))
done = True
elif(confirm == "N"):
action = input("What do you want to do? [Append/Delete]")
if(action == "Append"):
appending(mylist)
done = False
elif(action == "Delete"):
removing(mylist)
done = False
def appending(mylist1 = []):
print("Please type EOF when you want to stop!")
while True:
c = input("Please enter EOF to stop adding. Please enter a choice: ")
if(c=="EOF"):
break
else:
mylist1.append(c)
print("You have inserted {} choices".format(len(mylist1)))
print("Please verify them below: ")
for x in range(0, len(mylist1)):
print(mylist1[x])
def removing(mylist2 = []):
print("Following are choices: ")
r = input("What do you want to remove? ")
mylist2.remove(r)
print("{} successfully removed!".format(r))
现在的问题是我无法在追加或删除函数中调用choices()
,因为choices()函数将无限次地调用append。
那么如何在列表中追加或删除数据后重新选择?
答案 0 :(得分:1)
正如tobias_k所建议的那样,您应该将choices()
的内容添加到while循环中。
我也找到了
其他一些问题:
False
不等于"False"
,因此您的while
循环永远不会运行。mylist
,mylist1
和mylist2
等字词 - 最好将这些字词重命名为choosing_list
,appending_list
和{ {1}},所以它更清楚。以下是解决了这些问题的代码:
removing_list
如果此代码存在任何问题,请与我们联系。