To elaborate on comments from Nin17 and molbdnilo:
Your function function(n) is supposed to return an integer value.
Like you did in if branch with return(n**2), do return in the else branch:
def function(n):
if n % 4 == 1:
return n**2
else:
return function(n + 1) # inlined the increased n and do return
I would recommend to give the function a meaningful name.
A function like yours that calls itself is a recursive function. One of it’s key-mechanisms is that it returns a value.
1
solved Function is returning NoneType in Python instead of integer [closed]