Search code examples
pythonnegative-number

Is there a way I can show the "imaginary" negative numbers or whatever numbers are missing past the 33rd integer?


# This is the original code beginning with the number 777 and I want to show the first 37 numbers.

def Collatz(n):
    i = 1
    while n != 1:
        print(f'{i}. {n}')
        if n & 1:
            n = 3 * n + 1
        else:
            n = n // 2
        i+=1

 
Collatz(777) 

I want it to go past and stop at the 37th number. (which probably means that the numbers are imaginary, or negative.)

  1. 2

  2. ....


Solution

  • Collatz = 777 
    i = 1
    while i != 38:
        print(f'{i}. {Collatz}')
        if Collatz & 1:
                Collatz = 3 * Collatz + 1
    else:
        Collatz = Collatz // 2
    i+=1