Home > Blockchain >  Python | Trying to verify input is within list
Python | Trying to verify input is within list

Time:11-24

I'm trying to figure out why this code isn't exiting the program upon entering one of the exit commands within the created list.

from sys import exit

Exit_Commands = [
    "Exit"
    "exit"
    "Goodbye"
    "goodbye"
    "Bye"
    'bye'
]

Alive = True

while Alive:
    User_Input_From_Console = input()

    if User_Input_From_Console in Exit_Commands:
        print("Exiting Program")
        exit()

CodePudding user response:

Add commas to your list:

Exit_Commands = [
    "Exit",
    "exit",
    "Goodbye",
    "goodbye",
    "Bye",
    'bye'
]

Without commas, all your strings were being implicitly concatenated together.

CodePudding user response:

from sys import exit

Exit_Commands = [
    "Exit",
    "exit",
    "Goodbye",
    "goodbye",
    "Bye",
    'bye',
]

Alive = True

while Alive:
    User_Input_From_Console = input()

    if User_Input_From_Console in Exit_Commands:
        print("Exiting Program")
        exit()

Maybe this will work i am not 100% sure as i am also noob.

  • Related