import math


def root_mean_squared_error(LeadDay,df,model,observed):
    """
    Args:
        LeadDay: specifically applies to forecast models with lead times
         if no lead day is available input None
         LeadDay is desired Lead day (int)
        df: data frame where Observed and Model data is found
        model & observed : column name (string)
        
    Return: Root Mean Squared Error
    Function:
        subtract model values from observed 
        square result and sum all squares 
        divide by number of values
    """
    count = 0
    total = 0
    
    if LeadDay is None:
        for a, j in zip(df[observed], df[model]):
            diffsquared = ((j) - (a))**2
            total += diffsquared
            count +=1
    else:
        for a, j in zip(df[LeadDay][observed], df[LeadDay][model]):
            diffsquared = ((j) - (a))**2
            total += diffsquared
            count +=1
    avg = total/count

    return math.sqrt(avg)