So currently I'm working with user-defined functions. Initially, the code inside the user-defined function worked but when I attempted to change it into a user-defined function, it produces incorrect values.
No need for any equations
The Attempt at a Solution
If I were to remove the code within the user-defined function, the code gives a value of M around 1.7361319160639026, which is correct. But for some reason when I execute this code (as a user-defined function), I get values of M which are far too low. I'm slightly confused toward why this happens.
from math import sqrt from matplotlib import pyplot as plt from pylab import plot, show def function(L): M = 0.0 for i in range(-L,L+1): for j in range(-L,L+1): for k in range(-L,L+1): if not (i==j==k==0): M = ((-1)**(i+j+k+1))/sqrt(i*i +j*j +k*k) return M list =  L = 0 while int(L) < 50: list.append(L) L = int(L) + 1 print(function(L))