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

2024-09-28 05:28:33 发布

您现在位置:Python中文网/ 问答频道 /正文

你好,我做了这个程序,要求用户输入选择打印,排序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
  • 选择“退出”的预期结果是程序停止
  • 实际结果是程序打印“请输入有效选项”,然后退出

如果输入了一个未声明的选项,如何将其修改为只打印该字符串?你知道吗


Tags: or程序if排序passquitprintchoice

热门问题