Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

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

OCA Oracle Database SQL Exam Guide Exam 1Z0-071

Authors: Steve O'Hearn

1st Edition

1259585492, 978-1259585494

More Books

Students also viewed these Databases questions