我有一个问题,当我使用代码并写下“否”时,我的程序会将其添加到列表中,而不是移动到<>;没有添加“no”的块。
listagosci = []
print("Party list: ")
for i in range(3):
n5 = input("enter name of guest: ").title()
listagosci.append(n5)
n5 = input("Would You like to add another guest? (yes/no): ").title()
while n5 != "No":
n5 = input("enter name of guest, if no, eneter \"no\": ").title()
listagosci.append(n5)
else:
print(listagosci, len(listagosci))
我创建的解决方案可以在else之后添加listagosci.remove(-1)-但在我看来,程序不应该添加这个“no”。
我也知道,当有人在n5输入中写一些不同于yes/no的东西时,没有if语句,但我现在不需要它。
我尝试了我所知道的一切(我是初学者)。