'Trying to print all dimensions of a sphere that satisfies a certain condition, function is not printing all instances

I'm supposed to write code that prints the total number of integer solutions to the inequality x^2 + y^2 + z^2 <= n, where n is a user-inputted integer that is between 1 and 2000 (inclusive). Here is my code so far:

import math
n = int(input("Please enter an integer between 1 and 2000: "))
rad = int(math.sqrt(n))
sphere_combos = []

def sphereCombos(radius):
  count = 0
  for x in range(-radius, radius + 1):
    
      for y in range(-radius, radius + 1):
          
          for z in range(-radius, radius + 1):
             sphere_combos.append((x, y, z))
  for x,y,z in sphere_combos:
    if x**2 + y**2 + z**2 <= n:
      count = count + 1
  return count

total_methods = 0
for i in range(0, rad + 1):
  total methods = total_methods + sphereCombos(i)

print(total_methods)

For some reason, it only prints sphereCombos(rad), and I'm not sure why. It should print all of them cumulatively for numbers 1 to n. For example, n = 1 should give you 7. n = 2 alone gives 19, but it should give 26 (19+7). What am I doing wrong?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source