def prompt_choice(length, select_action, per_page):
    """
    Prompt the user for a choice of entry, to continue or to quit.

    An invalid choice will repeat the prompt.

    @param length: the largest choosable value
    @param select_action: description of what choosing an entry will result in.
    @param per_page: number of results to offer next. Set to 0 to hide "next"
        option.
    """
    prompt = 'What do you want to do? [{0}] to {1}, {2}[Q]uit: '.format(
        '1' if length == 1 else '1–{length}',
        select_action,
        '[N]ext {per_page}, ' if per_page else '')
    while True:
        choice = input(prompt.format(length=length, per_page=per_page))
        try:
            int_choice = int(choice)
        except ValueError:
            int_choice = None

        if choice.lower() == 'n' and per_page:
            return None
        elif choice.lower() == 'q':
            exit(0)
        elif int_choice and (1 <= int_choice <= length):
            return int_choice
        else:
            print('Invalid choice. Try again!')