WHILE关键字因语法错误而突出显示。当我使用FOR循环时,IF语句中的冒号因语法错误而突出显示

问题描述 投票:-2回答:1

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()
python-3.x loops syntax syntax-error syntax-highlighting
1个回答
-1
投票

这里您不需要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()
© www.soinside.com 2019 - 2024. All rights reserved.