试图退出程序,进入死循环(Python)
Trying to exit the program, get endless loop (Python)
我是初学者,试图退出我在 Python 中的第一个程序,但只是陷入无限循环。
不明白怎么回事。
question = input("Please enter your 'to do' list: ")
some_list = []
while True:
if question not in some_list:
some_list.append(question)
question = input("Please enter your 'to do' list: ")
else:
print("\n\nPress enter to exit")
print(some_list)
首先,永远不要使用 built is 函数作为变量。您基本上是将数字 4 分配给数字 5:4=5。这是错误的。我修好了。
question = input("Please enter your 'to do' list: ")
something = []
while True:
if question not in something:
something.append(question)
question = input("Please enter your 'to do' list: ")
else:
print("\n\nPress enter to exit")
print(something)
`
question = input("Please enter your 'to do' list: ")
list = []
while True:
if question not in list:
list.append(question)
question = input("Please enter your 'to do' list: ")
else:
input("\n\nPress enter to exit")
print(list)
break
欢迎光临!
如果你想像你在其中一张印刷品中写的那样打破循环:“\n\nPress enter to exit”,你可以使用以下解决方案:
while True:
x = input()
if len(x) == 0:
break
完整代码为:
question = input("Please enter your 'to do' list: ")
list = []
while True:
question = input("Please enter your 'to do' list: ")
if len(question) == 0:
break
if question not in list:
list.append(question)
print(list)
question = input("Please enter your 'to do' list: ")
alist = []
while True:
if question not in alist:
alist.append(question)
question = input("Please enter your 'to do' list/type 'quit' to exit: ")
if question=='quit':
break
print(alist)
我是初学者,试图退出我在 Python 中的第一个程序,但只是陷入无限循环。 不明白怎么回事。
question = input("Please enter your 'to do' list: ")
some_list = []
while True:
if question not in some_list:
some_list.append(question)
question = input("Please enter your 'to do' list: ")
else:
print("\n\nPress enter to exit")
print(some_list)
首先,永远不要使用 built is 函数作为变量。您基本上是将数字 4 分配给数字 5:4=5。这是错误的。我修好了。
question = input("Please enter your 'to do' list: ")
something = []
while True:
if question not in something:
something.append(question)
question = input("Please enter your 'to do' list: ")
else:
print("\n\nPress enter to exit")
print(something)
`
question = input("Please enter your 'to do' list: ")
list = []
while True:
if question not in list:
list.append(question)
question = input("Please enter your 'to do' list: ")
else:
input("\n\nPress enter to exit")
print(list)
break
欢迎光临! 如果你想像你在其中一张印刷品中写的那样打破循环:“\n\nPress enter to exit”,你可以使用以下解决方案:
while True:
x = input()
if len(x) == 0:
break
完整代码为:
question = input("Please enter your 'to do' list: ")
list = []
while True:
question = input("Please enter your 'to do' list: ")
if len(question) == 0:
break
if question not in list:
list.append(question)
print(list)
question = input("Please enter your 'to do' list: ")
alist = []
while True:
if question not in alist:
alist.append(question)
question = input("Please enter your 'to do' list/type 'quit' to exit: ")
if question=='quit':
break
print(alist)