Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Turn in the following Python programs (only the .py files) along with their output: ___________________________________________________________________________________________ Problem 1 (20 pts) For this problem, you may NOT

Turn in the following Python programs (only the ".py" files) along with their output: ___________________________________________________________________________________________

Problem 1 (20 pts) For this problem, you may NOT alter the original list. Write the function repeats_list(myList) which takes a list of integers and returns a list of the integers which appear more than once in the original list. For example, repeats_list([4, 17, 6, 20, -17, 3, 6, 8, -17, 20, 9, 9]) would return the list [-17, 6, 9, 20]. Use the list method "sort" before returning your new list. Note that repeated values appear only once in the list returned. ___________________________________________________________________________________________

Problem 2 (20 pts) Write the function expand(data, one_list) which that takes a list of integers called data, and a boolean one_list. If one_list is False, the function returns a list of lists, the first of which is data[0] copies of data[0], the second of which is data[1] copies of data[1], etc. For example, expand([2, 5, 3, 1], False) would return [[2, 2], [5, 5, 5, 5, 5], [3, 3, 3], [1]] expand([2, 5, 3, 1], True) would return [2, 2, 5, 5, 5, 5, 5, 3, 3, 3, 1] For full credit, you may NOT use list indices! (You can get at most 12 points if you use list indices.)

Problem 3 (20 pts) Write the function sum_ignore(myList, a, b) which takes a lists of integers and distinct integers a and b. The function returns the sum of the elements in myList but ignores any sections of integers starting with a and ending with b (every a will be followed by at least one b). See the given output for sample calls. ___________________________________________________________________________________________

Problem 4 (20 pts) Write the method remove_multplies(myList) which takes a list of positive integers and removes integers from myList any integers that are multiples of any previous integer in myList. Note that this means the first number of any nonempty list is not removed. For example: The list [10, 9, 20, 2, 90, 15, 6] would be changed to [10, 9, 2, 15]. The list [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20] would be changed to [2, 3, 5, 7, 11, 13, 17, 19]. ___________________________________________________________________________________________

Problem 5 (20 pts) Write the function fullcopy(myList) which returns a list x which is equal to (==) but not the same as (is) myList, such that any changes to list x do not affect myList. You may want to use the function "isinstance". See output for sample runs. ___________________________________________________________________________________________

Problem 6 (GRAD STUDENTS required: 10 pts. UNDERGRADS: +3 extra credit pts) You have some blocks of length one inch, and some blocks of length five inches. Is it possible glue together some (or all) of these blocks to make a giant block that is goal inches long? For example, if you have 4 five-inch blocks and 3 one-inch blocks, it is possible to make a block of length 17 inches: by gluing together 3 five-inch blocks and 2 one-inch blocks. However, it is not possible to make a block of length 19 inches. Write the Boolean method giantBlockPossible(num1, num5, goal) The method returns True if it is possible to make a block of length goal using num1 one-inch blocks and num5 one-inch blocks. The method returns False otherwise. See sample runs. You may not use any loops or call any functions (so no recursion)!

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

More Books

Students also viewed these Databases questions

Question

Write formal proposal requests.

Answered: 1 week ago

Question

Write an effective news release.

Answered: 1 week ago

Question

Identify the different types of proposals.

Answered: 1 week ago