def promptyn(msg, default=None):
    while True:
        yes = "Y" if default else "y"
        if default or default is None:
            no = "n"
        else:
            no = "N"
        confirm = prompt("%s [%s/%s]" % (msg, yes, no), '').lower()
        if confirm in ('y', 'yes'):
            return True
        elif confirm in ('n', 'no'):
            return False
        elif len(confirm) == 0 and default is not None:
            return default
Display a blocking prompt until the user confirms
dataset/ETHPy150Open mathcamp/pypicloud/pypicloud/scripts.py/promptyn