我遇到了无法完成代码的问题。 在运行此代码时,它会出现一个IndexError问题。
<section id="aboutuspic">
<div class="container">
<img src="inside.jpg" />
</div>
</section>
name = str(input("Please input the books name that you would like to borrow: ")
file = open("books.txt","r")
file_contents = []
for line in file:
stripped_line = line.strip()
line_list = stripped_line.split()
file_contents.append(line_list)
file.close()
i = 0
for name in range(len(file_contents)):
i = i +1
if name == file_contents[i]:
table_3= [["Borrow Book","1"],["Cancel Borrowing","2"]]
headers_3 = ["Details","No."]
print(tabulate(table_3,headers_3,tablefmt = "grid"))
num = int(input("Please input 1 for confirmation of booking and 2 for canceling the booking: "))
file_contents[i] = changed_name
changed_name = str(changed_name)
if name == file_contents[i]:
IndexError: list index out of range