Python 为什么我的程序会在我有时间的时候打印这个字符串!=一串

Python 为什么我的程序会在我有时间的时候打印这个字符串!=一串,python,if-statement,while-loop,Python,If Statement,While Loop,您好,我制作了这个程序,要求用户输入打印、排序1、排序2或退出选项 usrinpt=0 while usrinpt != "quit": #if usrinpt == quit then no if statements right? usrinpt = input("Enter choice Print, Sort1 (distance), Sort2 (price) or Quit : ") usrinpt = usrinpt.lower() if usrin

您好,我制作了这个程序,要求用户输入打印、排序1、排序2或退出选项

usrinpt=0

while usrinpt != "quit":    #if usrinpt == quit then no if statements right?
    usrinpt = input("Enter choice Print, Sort1 (distance), Sort2 (price) or Quit : ")
    usrinpt = usrinpt.lower()
    if usrinpt == "print":
        PrintList(mat)
        pass
    elif usrinpt == "sort1":
        SelectionSortDistorPrice(mat,0)
        PrintList(mat)
        pass
    elif usrinpt == "sort2":
        SelectionSortDistorPrice(mat, 1)
        PrintList(mat)
       pass
    elif usrinpt != "quit"or"sort1"or"sort2":   #why does it print the string even when i enter quit?
        print("please enter a valid choice")
        pass
  • 选择“退出”的预期结果是程序停止
  • 实际结果是程序打印“请输入有效选项”,然后退出

如果输入了未声明的选项,如何将其修复为仅打印该字符串?

elif usrinpt not in[“quit”、“sort1”、“sort2]:
请修复缩进。缩进哪里不正确?我明白了