lundi 9 mars 2020

python else: do nothing

I would like my program to no nothing if user selects option in menu that does not exist.

def mainMenu():
    os.system("clear")
    print("menu")
    print("1 - option 1")
    print("2 - option 2")   
    selection=str(raw_input(""))
    if selection=='1':
        some super-interesting things
    if selection=='2':
        Kim Kardashian with Eskimo riding a polar bear
    else: 
        literally DO NOTHING, no changes, no exiting the program, just takes the input and waits for another command
mainMenu()

How to achieve that? 'pass' or 'return' causes to exit the program. 'mainMenu()' causes refreshing menu "page"

Aucun commentaire:

Enregistrer un commentaire