Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed
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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David Kroenke, David Auer, Scott Vandenberg, Robert Yoder

8th Edition

013460153X, 978-0134601533

More Books

Students also viewed these Databases questions