lightcli.py
def choice_input(options=[], prompt='Press ENTER to continue.', 
        showopts=True, qopt=False):
    """Get input from a list of choices (q to quit)"""

    choice = None
    if showopts:
        prompt = prompt + ' ' + str(options)
    if qopt:
        prompt = prompt + ' (q to quit)'
    
    while not choice:
        try:
            choice = string_input(prompt + ' ')
        except SyntaxError:
            if options == []:
                pass
        if choice:
            if choice in options:
                return choice
            elif qopt == True and choice == 'q':
                choice = None
                is_sure = string_input('Are you sure you want to quit? ')
                if is_sure in ('Y', 'y', 'yes'):
                    exit('\nThanks for playing. Goodbye.\n')
            elif options == []:
                return 0
            else:
                print('Answer must be one of ' + str(options) +
                        '. Your answer?')
                if options:
                    choice = None
        elif options == []:
            return 0
        else:
            print('Answer must be one of ' + str(options) + 
                    '. Your answer?')
def choice_input(options=[], prompt='Press ENTER to continue.', 
        showopts=True, qopt=False):
    """Get input from a list of choices (q to quit)"""

    choice = None
    if showopts:
        prompt = prompt + ' ' + str(options)
    if qopt:
        prompt = prompt + ' (q to quit)'
    
    while not choice:
        try:
            choice = string_input(prompt + ' ')
        except SyntaxError:
            if options == []:
                pass
        if choice:
            if choice in options:
                return choice
            elif qopt == True and choice == 'q':
                choice = None
                is_sure = string_input('Are you sure you want to quit? ')
                if is_sure in ('Y', 'y', 'yes'):
                    exit('\nThanks for playing. Goodbye.\n')
            elif options == []:
                return 0
            else:
                print('Answer must be one of ' + str(options) +
                        '. Your answer?')
                if options:
                    choice = None
        elif options == []:
            return 0
        else:
            print('Answer must be one of ' + str(options) + 
                    '. Your answer?')
def choice_input ( options = [ ] , prompt = 'Press ENTER to continue.' , showopts = True , qopt = False ) : choice = None if showopts : prompt = prompt + ' ' + str ( options ) if qopt : prompt = prompt + ' (q to quit)' while not choice : try : choice = string_input ( prompt + ' ' ) except SyntaxError : if options == [ ] : pass if choice : if choice in options : return choice elif qopt == True and choice == 'q' : choice = None is_sure = string_input ( 'Are you sure you want to quit? ' ) if is_sure in ( 'Y' , 'y' , 'yes' ) : exit ( '\nThanks for playing. Goodbye.\n' ) elif options == [ ] : return 0 else : print ( 'Answer must be one of ' + str ( options ) + '. Your answer?' ) if options : choice = None elif options == [ ] : return 0 else : print ( 'Answer must be one of ' + str ( options ) + '. Your answer?' )
Get input from a list of choices (q to quit)
Get input from a list of choices ( q to quit )