The World’s Largest Online Community for Developers
Starting with integer
n, return both its length and its largest element for a hailstone sequence. i.e when
nis 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
num = int(input(" Enter a integer : ")) def seq(n): assert n > 0 print(n) if n == 1: return 1 elif n % 2 == 0: return seq(n // 2) else: return 1 + seq(3 * n + 1) result = seq(num) print(result)
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