I'm guessing that there is a scope issue here that I missed somewhere. This function squares all of the numbers and adds them together. It should stop if the number hits 1 or 89, otherwise keep going. Here's my code:
count = 0
def chain(x,count):
x = str(x)
temp = 0
for let in range(0,len(x)):
temp = temp + (int(x[let]) ** 2)
x = temp
print("\n")
print(temp)
if x == 89:
count = count + 1
print(count)
elif x == 1:
return False
else:
chain(x, count)
chain(145, 0)
print(count)
The problem is, when I print count when x == 89, I get 1. But when I print count at the end, it comes out as 0. I've looked over and I don't seem to be setting it to anything else, and I've also tried adding in return, return count, return True, and nothing seems to fix it. If someone could point out my error, I would greatly appreciate it!