尝试退出程序,得到无限循环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

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...