Answers for "collatz conjecture python"

0

collatz conjecture python

def collatz(n):
  	print(n) # Print number for output
	if n >= 1:
      if n % 2 == 0:
          collatz(n / 2)
      else:
        collatz(n * 3 + 1)


collatz(5)
# Ouptut:
# 16
# 8 
# 4 
# 2
# 1
Posted by: Guest on August-21-2021

Python Answers by Framework

Browse Popular Code Answers by Language