Question: (1) (20 points) Consider the function F:N + N given by 3n+1, if n is odd, n/2, if n is even F(n)= { Write Python

 (1) (20 points) Consider the function F:N + N given by

(1) (20 points) Consider the function F:N + N given by 3n+1, if n is odd, n/2, if n is even F(n)= { Write Python code to accomplish the following: (i) Write a Python function named F3n1 which takes a positive integer n, and computes and returns the integer value F(n) as defined above (use the integer division operator For F3n1 (10) should return 5 and F3n1(5) should return 16. 17 instead of the ordinary division operator). If , (ii) Write a Python function named sequence which takes a positive integer n and returns a list containing the sequence n, F(n), F(F(n)), F(F(F(n))),... up to and including the first occurrence of a 1. For example, the command print sequence(10) should give the output (10, 5, 16, 8, 4, 2, 1] You should use the function F3n1 you wrote for Part (i). (iii) Below those two functions, insert the following code, which I will use to test your functions. N = int(input("Enter a positive integer n:")) seq = sequence (N) print("The resulting sequence is: {0}", format (seq)) print ("It has length {0}", format (len(seq)))

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!