Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Given an index k, return the kth row of the Pascal's triangle. Pascal's triangle : To generate A[C] in row R, sum up A'[C] and

Given an index k, return the kth row of the Pascal's triangle.

Pascal's triangle : To generate A[C] in row R, sum up A'[C] and A'[C-1] from previous row R - 1.

Example:

Input : k = 3

Return : [1,3,3,1]

NOTE : k is 0 based. k = 0, corresponds to the row [1].

Note:Could you optimize your algorithm to use only O(k) extra space?

Please doanswer all the questions with proper explanation, I need code for above cp question and it should pass all large and corner test cases, I need explanation for each mcq below. Please don't copy

1. What will be the output of the following Python code?

def f(p, q, r):

global s

p = 10

q = 20

r = 30

s = 40

print(p,q,r,s)

p,q,r,s = 1,2,3,4

f(5,10,15)

a) 1 2 3 4

b) 5 10 15 4

c) 10 20 30 40

d) 5 10 15 40

2. An exception is ____________

a) an object

b) a special function

c) a standard module

d) a module

3. What will be the output of the following Python code?

a={1:"A",2:"B",3:"C"}

b=a.copy()

b[2]="D"

print(a)

a) Error, copy() method doesn't exist for dictionaries

b) {1: 'A', 2: 'B', 3: 'C'}

c) {1: 'A', 2: 'D', 3: 'C'}

d) "None" is printed

4. What is the difference between r+ and w+ modes?

a) no difference

b) in r+ the pointer is initially placed at the beginning of the file and the pointer is at the end for w+

c) in w+ the pointer is initially placed at the beginning of the file and the pointer is at the end for r+

d) depends on the operating system

5. If a is a dictionary with some key-value pairs, what does a.popitem() do?

a) Removes an arbitrary element

b) Removes all the key-value pairs

c) Removes the key-value pair for the key given as an argument

d) Invalid method for dictionary

6. What is the interval of the value generated by the function random.random(), assuming that the random module has already been imported?

a) (0,1)

b) (0,1]

c) [0,1]

d) [0,1)

7. What does os.close(f) do?

a) terminate the process f

b) terminate the process f if f is not responding

c) close the file descriptor f

d) return an integer telling how close the file pointer is to the end of file

8. Which are the advantages of functions in python?

a) Reducing duplication of code

b) Decomposing complex problems into simpler pieces

c) Improving clarity of the code

d) All of the mentioned

9. Does Lambda contains return statements?

a) True

b) False

10. What will be the output of the following Python code?

y = 6

z = lambda x: x * y

print z(8)

a) 48

b) 14

c) 64

d) None of the mentioned

11. The following Python code will result in an error if the input value is entered as -5.

assert False, 'Spanish'

a) True

b) False

12. Which keyword is used for function?

a) Fun

b) Define

c) Def

d) Function

13. Which of the following is not an advantage of using modules?

a) Provides a means of reuse of program code

b) Provides a means of dividing up tasks

c) Provides a means of reducing the size of the program

d) Provides a means of testing individual parts of the program

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

Students also viewed these Programming questions