def get_input_of_type(message, expected_type, allowed_inputs=None):
    """Generic function to receive user input of an expected type and restrict to a subset of inputs.
    Args:
        message             message to display to prompt user for input
        expected_type       type of input expected
        allowed_inputs      iterable of allowed input values
    """
    while True:
        try:
            user_input = expected_type(input(message))
            if allowed_inputs:
                if user_input in allowed_inputs:
                    break   # correct input type and part of allowed inputs
                print('Unexpected input')
                continue
            break
        except (ValueError, TypeError):
            print("Wrong type of input")
    return user_input