Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python Define a new function named collatz that will create a sequence of numbers that starts with a specified value.Initialize a list so it contains

Python

Define a new function named collatz that will create a sequence of numbers that starts with a specified value.Initialize a list so it contains only the value passed as a parameter. Then use a while loop to extend the list usingthe following process: Let n be the value currently at the end of the list. If n is even, extend the list with n , but if 2 n is odd, extend the list with 3 n + 1. An unproven conjecture from number theory is that eventually the number 1 will be appended to the list, which is when the process terminates.

image text in transcribed

def collatz(data): # Fill in your code here for Part 3  return None # Change or replace this line 
if __name__ == "__main__": 
 print('Testing collatz() for 2: ' + str(collatz(2))) print('Testing collatz() for 5: ' + str(collatz(5))) print('Testing collatz() for 17: ' + str(collatz(17))) 

Examples: Function Call Return Value Collatz (2) 12, 11 Collatz (5) [5, 16, 8, 4, 2, 11 Collatz (17) [17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1]

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

Conceptual Database Design An Entity Relationship Approach

Authors: Carol Batini, Stefano Ceri, Shamkant B. Navathe

1st Edition

0805302441, 978-0805302448

More Books

Students also viewed these Databases questions

Question

What are the other economic side effects of accidents?

Answered: 1 week ago