3. The hailstone sequence starting at a positive integer n is generated by following two simple rules. If n is even, the next number in the sequence is n / 2. If n is odd, the next number in the sequence is 3*n + 1. Repeating this process, the hailstone sequence gets generated. Write a recursive function hailstone(n) which prints the hailstone sequence beginning at n. Stop when the sequence reaches the number 1 (since otherwise, we would loop forever 1, 4, 2, 1, 4, 2, …)

def hail(n):
print(n, end=” “)
if n == 1:
return
if n%2 == 0:
hail(n//2)
else:
hail(3*n+1)

hail(7)
print()
hail(8)

# Output
7 22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1
8 4 2 1