Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

please asap Write an iterative Python function called generate_i( n ) that generates a series or rows of numbers stored as sublists according to the

please asapimage text in transcribedimage text in transcribedimage text in transcribed

Write an iterative Python function called generate_i( n ) that generates a series or rows of numbers stored as sublists according to the following rules: Start by returning [1] for n=1 . Continue by returning [1, 1] for n=2 Each remaining row of values will thus continue to have one more value than the previous row. For example, the fifth row will have five values, while the fourth row has four. The values on both ends of the current row will always be 1 for n > 1. Starting with the second row, each internal cell will be the sum of the two cells diagonally right above that cell. . Hence, n such rows should be generated by generate_i( n ). Below is a pictorial description of the values that should be generated with the call generate_i( 6 ): 1 1 1 1 1 4 6 4 1 1 5 10 10 5 1 For example, take the row before last from the bottom. Both ends have 1 , as required. The first leftmost value after 1 is 4 , because, above it are cells i and 3 , whose sum is 4. The middle element of the last row to be generated for n=6 is 6 , because above it are two 3 S. Your generate_i( n ) function will return a list of lists, in which each sublist will store one of these rows of numbers, starting with 1 at the top. Therefore, the return value of generate_i( 6 ) should be [[1], [1, 1], [1, 2, 1], [1, 3, 3, 1], [1, 4, 6, 4, 1], [1, 5, 10, 10, 5, 1]] where each row is represented by a sublist. So there are 6 sublists for n=6 . As mentioned above, your generate_i() function must be iterative, that is, it must strictly use looping to do its job. You are not allowed to use import statements or the zip() function. If you do, your grade will automatically be zero. You are not allowed to define additional functions! So you should only define generate_i() in your solution. If you define additional helper functions external or internal to generate_i(), they will be automatically detected, and, unfortunately, your grade will be zero. You will use the Jupyter Notebook file magic directive (%%file from the top of the following code cell. ... ) to store your solution as generate_i.py. Therefore, do not remove this directive TEST #1.1 (10 points) # # # from generate_i import generate_i student_answer = generate_i( 1 ) correct answer = [[1]] assert student_answer == correct_answer # TEST #1.2 (10 points) # # from generate_i import generate_i student_answer = correct answer = generate_i( 2 ) [[1], [1, 1]] assert student_answer == correct answer # TEST #1.3 (40 points) # # from generate_i import generate_i student_answer = generate_i( 6 ) correct answer = [[1], [1, 1], [1, 2, 1), (1, 3, 3, 1], [1, 4, 6, 4, 1], [1, 5, 10, 10, 5, 1]] assert student_answer == correct

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

Marketing Database Analytics

Authors: Andrew D. Banasiewicz

1st Edition

0415657881, 978-0415657884

More Books

Students also viewed these Databases questions

Question

Explain all drawbacks of application procedure.

Answered: 1 week ago