def query_yes_no(question, default=''):
    """Ask a yes/no question via raw_input() and return their answer.
    
    "question" is a string that is presented to the user.
    "default" is the presumed answer if the user just hits <Enter>.
        It must be "yes" (the default), "no" or None (meaning
        an answer is required of the user).

    The "answer" return value is one of "yes" or "no".
    """
    valid = {"yes":"yes",   "y":"yes",  "ye":"yes",
             "no":"no",     "n":"no"}


    exact = False
    if default == None:
        exact = True
    
    if exact:
        prompt = ("yes","no")
        valid = {"yes":"yes", "no":"no"}
    elif not default:
        prompt = ('y','n')
    elif default == "y":
        prompt = ('Y','n')
    elif default == "n":
        prompt = ('y','N')
    elif default == "yes":
        prompt = ('Yes','no')
    elif default == "no":
        prompt = ('yes','No')
    else:
        raise ValueError("invalid default answer: '%s'" % default)

    while 1:
        print question + " [%s/%s] " % (prompt[0],prompt[1])
        choice = raw_input().lower()
        if exact and choice in valid:
            return choice
        elif default and choice == '':
            return valid[default]
        elif not exact and choice in valid.keys():
            return valid[choice]
        else:
            print "Please respond with '%s' or '%s'" % (prompt[0].lower(), prompt[1].lower())
dataset/ETHPy150Open mirskytech/ansible-role-manager/arm/prompt.py/query_yes_no/original