def analyze_friends(names, phones, all_areacodes, all_places) :
    """
    names: tuple of friends names
    phones: tuple of phone numbers without special characters
    all_areacodes: tuple of area codes
    all_places: tuple of states
    Prints how many friends you have and every unique state, represeneted
    by phone number
    """
    def get_unique_area_codes():
        """
        Returns a tuple of all unique area codes in phones
        """
        area_codes = ()
        # phones is the parameter to analyze_friends
        for p in phones :
            if p[0:3] not in area_codes :
                area_codes += (p[0:3], )
        return area_codes

    def get_states(some_areacodes) :
        """
        some_areacodes: tuple of area codes
        Returns a tuple of states associated with some_areacodes
        """
        states = ()
        for ac in some_areacodes :
            if ac not in all_areacodes :
                states += ("BAD AREACODE", )
            else :
                # use index to match ac with state
                index = all_areacodes.index(ac)
                states += (all_places[index], )
        return states

    num_friends = len(names)
    unique_area_codes = get_unique_area_codes()
    unique_states = get_states(unique_area_codes)

    print("You have", num_friends, "friends!")
    print("They live in:, ")
    for s in unique_states :
        print(s)