CLI prompts

Some shortcuts to asking various questions on the command line.

Simply waiting for the Enter key looks like this:

input("Press Enter to continue...")

Yes/no prompt

Waits for the user to enter a single key:

def yes_or_no(question):
    reply = str(input(question+' (y/n): ')).lower().strip()
    if reply[:1] == 'y':
        return True
    if reply[:1] == 'n':
        return False
    else:
        return yes_or_no("Please enter y or n.")

Open question

Lets the user enter a text.

def prompt(question):
    return str(input(question + ' ')).lower().strip()