如何解决尝试退出程序,得到无限循环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)
解决方法
首先,从不使用内置函数作为变量。您基本上是将数字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)
`
,欢迎光临! 如果您想像打印其中一张照片一样中断循环:“ \ n \ n按Enter退出”,则可以使用以下解决方案:
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)
,
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