user
Create a program that takes an array and outputs the largest element

[1, 3, 15, 20, 8, 9]


assistant
def largest_element(arr):
    """
    Takes an array of elements and returns the largest element in the array 

    Parameters:
    arr (list): Array of integers 

    Returns:
    largest (int): Largest element in array 
    """

    # Initialise largest as the first element in array
    largest = arr[0]

    # Iterate through rest of elements in array
    for i in range(1, len(arr)):
        # Update largest if element is larger
        if arr[i] > largest:
            largest = arr[i]
    # Return the largest element
    return largest