Below is the program written for hailstone sequence.
count = 0
def hailstone(n):
"""Print the terms of the 'hailstone sequence' from n to 1."""
assert n > 0
print(n)
if n > 1:
if n % 2 == 0:
hailstone(n / 2)
else:
hailstone((n * 3) + 1)
count = count + 1
return count
hailstone(10)
After debugging this program, I see that object referenced by count
that is part of global frame is not getting incremented within the function object hailstone
, as per the below observation:
Any reason, why count
does not get incremented?