**Click Here to Download this Answer Instantly**

A:Define a function,collatz(N), which takes in an integer valueNand returnsN//2 ifNis evenand 3∗N+1 ifNis odd.Problem B:Define a function,collatz_sequence(N), which takes in an integerNand returns the Collatzsequence forN. Recall that the Collatz sequence is a list which begins withNand ends with 1, i.e. the index0 value for Collatz sequence isNand the−1 index value is 1. Note: since you already defined in Problem Athe function which will the next term in the Collatz sequence, you should call that function in your code forProblem B.Problem C:Define a function,collatz_length(N), which takes in an integerNand returns the length ofthe associated Collatz sequence. Note: this can be done very quickly (requires one short line of code inside thefunction definition) by calling your code from Problem B.Problem D:Define a function,collatz_lengths(N)(note the plural ’s’ at the end) which takes in an integerNand returns a list of the lengths of the Collatz sequences from 1 up to N.