WHILE关键字因语法错误而突出显示。当我使用FOR循环时,IF语句中的冒号因语法错误而突出显示]
choice = int(input("Enter your choice. (Press 1 for adding a book. Press 2 for searching a book. Press 3 to clean the file. Press 0 for ending the program")
while choice !=0:
choice = int(input("Enter your choice. (Press 1 for adding a book. Press 2 for searching a book. Press 3 to clean the file. Press 0 for ending the program")
if choice == 1 :
Append_Book()
elif choice == 2 :
Search_by_Author()
elif choice == 3 :
Cleanfile()
这里您不需要while循环或for循环,因为您没有循环任何内容。改用if语句。在选择输入字符串的末尾也缺少括号。
# Replace while with if
if choice !=0:
# Add a bracket at the end
choice = int(input("Enter your choice. (Press 1 for adding a book. Press 2 for searching a book. Press 3 to clean the file. Press 0 for ending the program"))
if choice == 1:
Append_Book()
elif choice == 2:
Search_by_Author()
elif choice == 3:
Cleanfile()