Question: Use python3 to code the following program: This program simulates the up and down movement of a hailstone in a storm. The program should ask

Use python3 to code the following program:

This program simulates the up and down movement of a hailstone in a storm. The program should ask the user for an integer, which will be the starting height of the hailstone. Based on the current value of the height, the program will repeatedly do the following:

If the current height is 1 (or 0), quit the program

If the current height is even, cut it in half (divide by 2) If the current height is odd, multiply it by 3, then add 1

The program will keep updating the number, following the above rules, until the number is 1. It should print out the height of the hailstone at each step, including at the end.

Once the hailstone is at height 1 (or 0), the program should end, and print out that the hailstone stopped.

(HINT: Think carefully about the order in which the program checks each of the conditions, or it wont perform correctly.)

For example, given a starting value of 24, here are the numbers to output: 24 -> 12 -> 6 -> 3 -> 10 -> 5 -> 16 -> 8 -> 4 -> 2 -> 1 For this part of the homework, you can assume the following: The number will be positive (zero or greater than zero)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!