Answered step by step
Verified Expert Solution
Question
1 Approved Answer
1. Write Python code which computes the Hailstone path length of a positive integer. The Hailstone function is defined as: h(n) n/2, (3n +
1. Write Python code which computes the Hailstone path length of a positive integer. The Hailstone function is defined as: h(n) n/2, (3n + 1, = : {3n The Hailstone path for an integer n is the sequence of numbers generated by the Hailstone function, beginning at 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 1263105168421 n is even nis odd 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 - like this: n = input('Enter a value for n ') n int (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 2 1 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
Step: 1
Sure Heres the Python code that computes the Hailstone path length of a positive integer python def ...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started