import click


def role_selection_is_valid(selection, account_roles):
    """Checks that the user input is a valid selection

    Args:
        selection: Value the user entered.
        account_roles: List of valid roles to check against.

    Returns:
        Boolean reflecting the validity of given choice.
    """
    err_msg = 'You selected an invalid role index, please try again'
    try:
        selection
    except ValueError:
        click.secho(err_msg, fg='red')
        return False

    if selection not in range(len(account_roles)):
        click.secho(err_msg, fg='red')
        return False

    return True