Collatz Conjecture in Python
See Python: Tips and Tricks for similar articles.
Just for fun, I wrote a Python script showing how the Collatz Conjecture works:
def collatz(num):
while num != 1:
print(num)
if num % 2 == 0:
num = int(num / 2)
else:
num = int(3 * num + 1)
else:
print(num)
print('Done!')
def main():
num = int(input('Input an integer: '))
collatz(num)
main()The script will output something like this:
Input an integer: 12 12 6 3 10 5 16 8 4 2 1 Done!
Enjoy!
