def category_validation(user_category, level_data_info):
    """
    Check if the category selected by the user exists in the level_data list.
    Returns the level number entered by the user, if it exists. 
    If the level entered doesn't exist, it returns an error message and exits the program.

    Params:
        1) user_category - This is the input received from the user
        2) level_data_info - This is the list containing the contents level_data.

    Examples:
        valid_category = category_validation(chosen_category, level_data)
        > valid_category = category_validation("animals", level_data)
        > valid_category = "animals"

        valid_category = category_validation(chosen_category, level_data)
        > valid_category = category_validation("animals", level_data)
        > "You chose an invalid category, please try again", exit()
    """

    count = 0
    for data in level_data_info:
        if data["category"] == user_category:
            count = count + 1
        else:
            pass
    
    if count == 0:
        return print("You chose an invalid category, please try again"), exit()
    else:
        return user_category