Collatz Conjecture Calculator!

This video by Veritasium on youtube explains the essence of the Collatz conjecture, but, to sum it up briefly:

However, this can be hard to do for larger numbers unassisted, so, I created a calculator for it in python. The calculator shows each step and at the end, the number of steps it took for the number inputted to reach 1. I showcase it here:

Here's the source code:

Here's how to make it:

  1. Create a game variable and set its value to True
    Make the program run when game is True. Since we won't be turing it off, the program will loop until killed

  2. Collect and input from the user and store the number in the variable n
    Since we'll be changing n, we need a way to keep the original value. To do this, we make a new variable called orig and make it equal the n (the input)
    The variables count, up and down store the steps the number takes to the loop. For now, we can set them all to 0 since we haven't yet started

  3. Because the conjecture states that all numbers will reach the 4, 2, 1 loop, we can check if the number is equal to 1 to know if we should carry on or not
    To check if the number is even or odd, we divide it by 2 and find the remainder. If it is 1, the number is odd and 0 makes the number even
     If the number is odd, we perform 3n + 1 on it, print the step and add 1 to the count and up variables because the number has gotten bigger
     If the number is even, we perorm n/2 instead, print the step and add 1 to the count and down variables because the number has gotten smaller

  4. Because of the condition controlled loop from before, all we need to do now is present our findings
    To do this, I put the original value, total step count and number of up and down steps in a sentence

  5. At the end, I decided to add a small section that would calculate the ratio of up to down step to see if any interesting patterns show up
    For that, you have to make sure that the original number wasn't 1 so you dont divide by 0. Once that is confirmed, you can divide up by down

  6. Mess around with it!

To learn more python, check out this tutorial!