Question: The real problems Consider the following algorithm that builds a sequence of integers. The input is a positive integer n The output is a sequence

 The real problems Consider the following algorithm that builds a sequence

The real problems Consider the following algorithm that builds a sequence of integers. The input is a positive integer n The output is a sequence 1. if is even, divide it by 2 2. if n is odd, multiply it by 3 and add 1 3. repeat until n is 1 For example, if you start with 10, the sequence you build is 10, 5, 16, 8, 4, 2,1 Or if you start with 100, the sequence is: 100,50,25,76,38,19,58,29,88,44,22,11,34,17,52,26,13,40,20,10,5,16,8,4,2,1 The amazing property of this sequence is that it always seems to converge to 1, no matter what n you start with. But none has been able to prove it: do so and you will be famous. If you get time at the end of the lab, try to figure out why it converges to 1. The sequence seems to know that 1 is its home, and eventually wends its way back home. You will write a function to explore this sequence. It will be a good test of recent Python syntax that we have developed, such as while loops and functions. Only the first function wll be graded. The rest are for fun and to satisfy your curiosity. Please do try them out. You will learn a lot that will be useful in future. And you only get better at coding by coding. Problem 4 Problem compute the length of the sequence Python script length seq py Python function to complete lengthSeq (it has a long docstring; please read it patiently) Additional test: add 1 more test of this function to driver_lab4.py

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!