Question: Exercise 7.2 (collatz.py, longest_collatz.py) For this exercise you will need to write two different Python modules. Make sure you follow the boilerplate requirements for both

 Exercise 7.2 (collatz.py, longest_collatz.py) For this exercise you will need to

Exercise 7.2 (collatz.py, longest_collatz.py) For this exercise you will need to write two different Python modules. Make sure you follow the boilerplate requirements for both programs, so that the two modules don't interfere with each other. The first program is collatz.py, which will contain the function collatz_len). This function will take in a starting number and will return the length of the Collatz sequence generated from it. The Collatz sequenc e be calculated from a starting number n with the following rules: 1. If n is even, set n equal to n/2. 13 CSE/IT 107L Lab 3: Defining Functions and Modules 2. If n is odd, set n equal to 3n -1 The sequence ends when n is equal to 1. Using these rules, the Collatz sequence generated from starting number 13 will be the following sequence. It has a length of 10. 13(13*3) + 1 = 40 (40/2-20 10 5 16 8 4 2 1 Example Input: 1 Enter a starting number 13 Output: 1 Length of Collatz sequence: 10 Next, longest collatz.py should determine which starting number, less than one million, produces the longest sequence. You should use the import statement to make use of the code you wrote in collatz.py for determining the length of one sequence Example Output 1 Longest chain is produced by X with a sequence of length X This problem was taken from Project Euler. For more information please see: https: //projecteulernet/problem=14

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!