Project: Hailstone steps
A hailstone sequence starts with a positive integer. If the number is even, divide it by two to get the next number. If it is odd, multiply it by three and add one. Repeat with each new number. Starting from 3, the sequence is 3, 10, 5, 16, 8, 4, 2, 1.
Write a function called hailstone_step that takes the starting number and
returns how many steps it takes to reach 1. Stop once you reach 1. A starting
value of 1 takes 0 steps. A starting value of 3 takes 7 steps. The function does
not print anything. It returns a value:
answer = hailstone_step(1000)
print(answer)
Splitting the work across several small functions can make code easier to read
and to test. You may do that here, but hailstone_step must still return the
count. Do not use recursion. You will write this function again with recursion in
Section 5.
Save the file as hailstone_step.py.
Show a solution
Try the project on your own first. This is one working solution, followed by its tests. Press Run to run the tests. Read them to see what thorough testing looks like, then change the solution and run again to watch a test fail.
Projects run on your own computer, so you tell us when you are done.