Question: 1. Write Python code which computes the Hailstone path length of a positive integer. The Hailstone function is defined as: n/2, n is even 3n

 1. Write Python code which computes the Hailstone path length of

1. Write Python code which computes the Hailstone path length of a positive integer. The Hailstone function is defined as: n/2, n is even 3n +1, n is odd h(n) The Hailstone path for an integer n is the sequence of numbers generated by the Hailstone function, beginning at n and ending at 1. The Hailstone path length is the number of integers that appear on the Hailstone path, which is 1 plus the number of applications of the Hailstone function required to reach h (n) = 1, For example, the Hailstone path for 12 is 12 6 3 10516 8- 42 1 Thus, the path length is 10. The function was applied 9 times. It is conjectured that all positive integers eventually reach 1 after repeated application of the Hailstone function. Although the conjecture is believed to be true, it has not yet been proven. Hint 1: use a while loop Hint 2: Use integer division://the double division slash Hint 2: The input function returns a string-you need to convert it to an integer using the int function- ike this: n-input'Enter a value for n ') Your output should look like this (for an input of 12): Enter a value for n 12 12 6 3 10 5 16 8 4 21 The path length is 10 steps Challenge: along with the path length, also find the largest number on the path

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!