To gain experience with nesting control structures.
The Collatz Conjecture states that if we take any integer $N$, and repeatedly do the following steps to it:
For example if we start with 5, we go though the following steps:
This conjecture was raised by mathematician Lothar Collatz in 1937. Every number anyone has ever tried has eventually gotten to 1, but mathematicians have not been able to prove if this will work for all numbers or not.
You should write a program which reads in the starting number and prints out the numbers in the sequence until you hit 1.
Below is an example run of how this program should work:
Enter a number: 3 3 10 5 16 8 4 2 Got to 1
For extra credit, make your program also print out the number of steps the process took. That would look like this:
Enter a number: 3 3 10 5 16 8 4 2 Got to 1 in 7 steps
When you are finished, please submit the .py file for the lab on Canvas. To do so, you'll need to navigate to where you saved the file on your computer.
Copyright © 2023 Ian Finlayson | Licensed under a Attribution-NonCommercial 4.0 International License.