Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

please only answer the questions 1-3 in the last picture, only write a small proof for the code and description of what occurs, thank you

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

please only answer the questions 1-3 in the last picture, only write a small proof for the code and description of what occurs, thank you

(1) (20 points) Consider the function F:N N given by 3n+1, if n is odd, n/2, if n is even 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 // instead of the ordinary division operator /). For example, F3n1(10) should return 5 and F3n1(5) should return 16. (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))) (1) Understand the problem (20%): Read and think about the problem description, and work out an example of your own choos- ing by hand. It should be a small' enough example that working it out by hand is reasonable, yet 'large enough' to capture most things that you think might happen. Include this in com- ments at the top of your Python program file. (II) Develop an approach: (20%): Explain, in words, how to solve a general instance of the problem by hand. Include this in comments at the top of your Python program file. (III) Test your approach by hand: (20%): Take the method you just described, and apply it to a different example by hand. Verify that it works correctly. Include this in comments at the top of your Python program file. (IV) Code it: (20%): Translate your "in words" method into Python code. (V) Test and debug: (20%): Attempt to use your code on the examples you already worked out by hand, and several more. Try hard to think of examples where something could fail. If it fails on any of those, determine whether the problem comes from (III) or (IV), by adding print statements, if necessary, and working the example by hand

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

Data Management Databases And Organizations

Authors: Richard T. Watson

3rd Edition

0471418455, 978-0471418450

More Books

Students also viewed these Databases questions

Question

Design a product and its production process

Answered: 1 week ago

Question

What is DDL?

Answered: 1 week ago