I am trying to write a recursive function which takes an integer as its parameter and returns the number of pairs of numbers within the integer that sum to 10. For example, findPairs(28164730) would return 3 because 2+8=10, 6+4=10, and 7+3=10.
This is what my code looks like now:
def find(x):
x = str(x)
count = 0
if str((10 - int(x[0]))) in x:
count = count + 1
x = x[1:]
find(x)
elif len(x) > 1:
x = x[1:]
find(x)
return count
The problem I am having is that the function will always return that the count is 1 because I am calling it again for recursion and it is setting the count back to 0 instead of just adding 1 to the count every time a pair is found. Does anyone know how I can fix this?