def choose(prompt, choices):
    """
    The user has to choose an element of *choices*.
    """
    # We add a list of the coices to the prompt. The items
    # index starts by 1.
    for i, choice in enumerate(choices):
        prompt += "\n{}. {}".format(i + 1, choice)
    prompt += "\n"

    # Let the user choose.
    while True:
        try:
            index = int(input(prompt)) - 1
            choice = choices[index]
        except KeyboardInterrupt:
            # This makes sure, that the user can still leave
            # the application by [ctrl + c].
            raise
        except:
            # Show the prompt again ...
            pass
        else:
            # Everything is ok: The user entered an integer
            # and the *index* is in the correct range: [0, len(choices)].
            # So we've got our value.
            break
    return (index, choice)