def maclaurin_cos_2x(value,k):
    """
    Compute maclaurin's series approximation for cos(2x).
    """
    
    global first_value
    first_value = 0.0
    
    #attempt to Approximate cos(2x) for a given value
    try:
        for item in xrange(4,k,4):
            next_value = (2**item)*(value*pi/180)**item/factorial(item)
            first_value += next_value
            
        for item in xrange(2,k,4):
            next_value = -1*(2**item)*(value*pi/180)**item/factorial(item)
            first_value += next_value
             
        return first_value +1

    #Raise TypeError if input is not a number
    except TypeError:
        print 'Please enter an integer or a float value'

    Compute maclaurin's series approximation for cos(2x).
    
recipes/Python/577344_Maclaurinsseriescos2x/recipe-577344.py