Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write an derative Python function called generate_1(n) that generates a series or rows of numbers stored as subists according to the following rules: Start by

image text in transcribed
image text in transcribed
Write an derative Python function called generate_1(n) that generates a series or rows of numbers stored as subists according to the following rules: Start by returning [1] for n1 . 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_1(n). Below is a pictorial description of the values that should be generated with the call generate_i( 6 ): OWY 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 1 and 3. whose sum is 4. The middle element of the last row to be generated for ne6 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_1( 6 ) should be [[1], (1, 1), (1, 2, 1), (1, 3, 3, 1), (1, 4, 6, 4, 1], [1, 5, 10, 18, 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 coping to do its job, . You are not allowed to use import statements or the zipo function. If you do, your grade will automatically be zero . You are not allowed to define additional functions So you should only define generate_10 in your solution. If you define additional helper functions external or internal to generate_10 they will be automatically detected and unfortunately your grade will be zero You will use the Jupiter Notebook file magic directive (Extile ... ) to store your solution as generate_1.py Therefore, do not remove this directive from the top of the following code cell PROVIDE YOUR ANSWER IN THE FOLLOWING CODE CELL In [ ]: xxFile generate_1.py def generate_1(n): Read above specifications carefully YOUR CODE HERE pass TEST CASES: 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 1 5 1

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

Professional Visual Basic 6 Databases

Authors: Charles Williams

1st Edition

1861002025, 978-1861002020

More Books

Students also viewed these Databases questions

Question

3.What are the Importance / Role of Bank in Business?

Answered: 1 week ago

Question

What is the difference between Needs and GAP Analyses?

Answered: 1 week ago

Question

What are ERP suites? Are HCMSs part of ERPs?

Answered: 1 week ago