Hailstone Numbers | function to print hailstone numbers and to calculate the number of steps required ; N is initially 1. ; N is reduced to 1. ; If N is Even . ; N is Odd . ; Driver Code ; Function to generate Hailstone Numbers ; Output : Number of Steps
def HailstoneNumbers ( N , c ) : NEW_LINE INDENT print ( N , end = " ▁ " ) NEW_LINE if ( N == 1 and c == 0 ) : NEW_LINE INDENT return c NEW_LINE DEDENT elif ( N == 1 and c != 0 ) : NEW_LINE INDENT c = c + 1 NEW_LINE DEDENT elif ( N % 2 == 0 ) : NEW_LINE INDENT c = c + 1 NEW_LINE c = HailstoneNumbers ( int ( N / 2 ) , c ) NEW_LINE DEDENT elif ( N % 2 != 0 ) : NEW_LINE INDENT c = c + 1 NEW_LINE c = HailstoneNumbers ( 3 * N + 1 , c ) NEW_LINE DEDENT return c NEW_LINE DEDENT N = 7 NEW_LINE x = HailstoneNumbers ( N , 0 ) NEW_LINE print ( " Number of Steps :   " , x ) NEW_LINE