def confirm ( question , default = True ) : valid = { "" : default , "yes" : True , "y" : True , "no" : False , "n" : False } while 1 : choice = input ( question + ( " [Y/n] " if default else " [y/N] " ) ) . lower ( ) if choice in valid : return valid [ choice ] print ( "Please respond with 'y' or 'n' " )
how to ask question in python then pick formula based on answer
Ask a yes / no question interactively .
def confirm(question, default=True):
    """Ask a yes/no question interactively.

    :param question: The text of the question to ask.
    :returns: True if the answer was "yes", False otherwise.
    """
    valid = {"": default, "yes": True, "y": True, "no": False, "n": False}
    while 1:
        choice = input(question + (" [Y/n] " if default else " [y/N] ")).lower()
        if choice in valid:
            return valid[choice]
        print("Please respond with 'y' or 'n' ")