The World’s Largest Online Community for Developers

'; python 3.x - Hailstone Sequence - LavOzs.Com

Starting with integer n, return both its length and its largest element for a hailstone sequence. i.e when n is even then n = n/2. while if number is odd then n= n*3+1, continue this loop until 1 is reached.

For example for n = 12, the result should be the pair 10 (length) and 16 (largest).

num = int(input(" Enter a integer : "))

def seq(n):

    assert n > 0
    if n == 1:
        return 1
    elif n % 2 == 0:
        return seq(n // 2)
        return 1 + seq(3 * n + 1)

result = seq(num)

I do not know how to print just the largest number and then followed by the length.

Say if the sequence is started with 5. I should display, largest number = 16 and length of sequence is 6.

Collatz sequence ends at 4
Can not return a list from a recursive function
Writing a perpetual program with Python to check validity of integers
Collatz Loop Structure
Could someone explain to me why the return statement should be included in this code?
Explore all sub-sequence
Looking to understand the logical breakdown of this code block
Take Value of Each Elemenet of STR Until # is Reached