jeudi 20 avril 2017

Why does my program print this string even when i have a while != string

Hello i made this program that asks the user to input the choices Print,sort1,sort2 or quit

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

  • expected outcome for the choice "quit" is for a the program to stop
  • actual outcome is that the program prints " please enter a valid choice" and then quits

how can i fix it to only print that string if a choice not stated is entered?

Aucun commentaire:

Enregistrer un commentaire