Python 我不想离开

Python 我不想离开,python,debugging,python-3.x,error-handling,Python,Debugging,Python 3.x,Error Handling,我是一个新手程序员,但我通常能发现这样的事情,所以我认为这是一个逻辑错误,而不是语法错误。所以我想知道你是否可以用你的新眼光来修正这个错误。代码是: database = open("database.txt", "r+") databaselist = database.readlines() length = len(databaselist) for i in range (length): database.readline() Continue = True while Co

我是一个新手程序员,但我通常能发现这样的事情,所以我认为这是一个逻辑错误,而不是语法错误。所以我想知道你是否可以用你的新眼光来修正这个错误。代码是:

database = open("database.txt", "r+")
databaselist = database.readlines()
length = len(databaselist)
for i in range (length):
    database.readline()

Continue = True
while Continue == True:
    Title = input("Enter title of book: ")
    Author = input("Enter author of book: ")
    Genre = input("Enter genre of book: ")
    Location = input("Enter the location of the book: ")
    TitleWrite = Title + "\n"
    AuthorWrite = Author + "\n"
    GenreWrite = Genre + "\n"
    LocationWrite = Location + "\n"
    database.write(str(TitleWrite))
    database.write(str(AuthorWrite))
    database.write(str(GenreWrite))
    database.write(str(LocationWrite))
    Continue2 = input("Would you like to continue? Y or N: ")
    if Continue2 == "n":
        Contine = False
        database.close()

您可以使用
break
语句中断循环。使用此选项,可以去掉
Continue
变量:

while True: # "infinite" loop that you will break out of
    title = ...
    author = ...

    response = input('Would you like to continue? Y or N: ')
    if response.lower() == 'n':
        database.close()
        break # break out of the "infinite" loop

(请注意,在Python中,标准是使用小写变量名)。

Typo
Contine
是一个不同于
Continue
的参数,谢谢。我会尝试一下,我相信它会起作用。PS-我知道这是正常的。lower()但是我在调试时删除了它,只是没有把它放回去