# POTD 15
# Author: <anonymized>
# Date: 11/16/25
# Description: Smooths a list of numbers to a mean using closest neighbors to average

def mean(nums):
    """ Return the arithmetic mean (i.e., average) of the list of numbers
    nums. Precondition: nums is not empty and contains only numbers.
    Does not modify its input (nums). """
    # count
    nums_int = 0
    for i in nums:
        # adds the value of i to a sum count
        nums_int += i
    #averages the count to get a mean value for the list
    nums_int = nums_int / len(nums)
    return nums_int
    
def smooth(nums):
    """ Return a smoothed copy of nums, where each element in the resulting
    list is the average of its old value and its two neighbors. The neighbor
    relation "wraps": that is, the first element's left neighbor should be the
    last element, and similarly the last element's right neighbor is the first
    element. For example, if we call smooth([a, b, c, d]), it should return a
    list [a', b', c', d'], where:
        a' is the average of d, a, and b
        b' is the average of a, b, and c
        c' is the average of b, c, and d
        d' is the average of c, d, and a
    Preconditions: nums contains only numbers and has length at least 3.
    This function does *not* modify the input list (nums)."""
    # create empty list
    n_list = []
    # indexes i in the list of numbers
    for i in range(len(nums)):
        # adds i and its neighbors together and averages them
        left_nbr = nums[i-1] # wraps to end w/ negative index
        right_nbr = nums[(i+1) % len(nums)] # wraps to beginning via mod
        
        avg = (left_nbr + nums[i] + right_nbr) / 3
        # appends i to the empty list, to create the smoothed list
        n_list.append(avg)
    return n_list

# print(smooth(nums))

def print_rounded(nums, end="\n"):
    """ Prints a list of numbers, rounded to the given number of decimal
    places. Does not modify nums. This function is provided for you
    and is only needed for use in the main program. You are not required
    to understand the details of how it works. """ 
    print("[", end="")
    for i in range(len(nums)-1):
        print(f"{nums[i]:3.2f}", end=", ")
    print(f"{nums[-1]:3.2f}]", end=end)

if __name__ == "__main__":
    pass