首页 > 解决方案 > 试图退出程序,得到无限循环(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)

标签: pythonloopsinfinite-loopexit

解决方案


首先,永远不要使用内置函数作为变量。您基本上将数字 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)

`


推荐阅读