Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Thanks in advance!! Give a N*N square matrix, return an array of its anti-diagonals. Look at the example for more details. Example: Input: 1 2

Thanks in advance!!

Give a N*N square matrix, return an array of its anti-diagonals. Look at the example for more details.

Example:

Input:

1 2 3

4 5 6

7 8 9

Return the following :

[

[1],

[2, 4],

[3, 5, 7],

[6, 8],

[9]

]

Input :

1 2

3 4

Return the following:

[

[1],

[2, 3],

[4]

]

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. Method issubclass() checks if a class is a subclass of another class.

a) True

b) False

2. What is the use of truncate() method in file?

a) truncates the file size

b) deletes the content of the file

c) deletes the file size

d) none of the mentioned

3. Which of the following refers to mathematical function?

a) sqrt

b) rhombus

c) add

d) rhombus

4. What is the current syntax of remove() a file?

a) remove(file_name)

b) remove(new_file_name, current_file_name,)

c) remove(() , file_name))

d) none of the mentioned

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

>>> b={}

>>> all(b)

a) { }

b) False

c) True

d) An exception is thrown

6. Which function is used to write a list of string in a file?

a) writeline()

b) writelines()

c) writestatement()

d) writefullline()

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

import sys

sys.argv[0]

a) Junk value

b) ' '

c) No output

d) Error

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

class A:

def init(self,x):

self.x = x

def count(self,x):

self.x = self.x+1

class B(A):

def init(self, y=0):

A.init(self, 3)

self.y = y

def count(self):

self.y += 1

def main():

obj = B()

obj.count()

print(obj.x, obj.y)

main()

a) 3 0

b) 3 1

c) 0 1

d) An exception in thrown

9. Which of the following is not a valid namespace?

a) Global namespace

b) Public namespace

c) Built-in namespace

d) Local namespace

10. Which of the following pattern matching modifiers permits whitespace and comments inside the regular expression?

a) re.L

b) re.S

c) re.U

d) re.X

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

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

>>> a.items()

a) Syntax error

b) dict_items([('A'), ('B'), ('C')])

c) dict_items([(1,2,3)])

d) dict_items([(1, 'A'), (2, 'B'), (3, 'C')])

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

class A:

def one(self):

return self.two()

def two(self):

return 'A'

class B(A):

def two(self):

return 'B'

obj1=A()

obj2=B()

print(obj1.two(),obj2.two())

a) A A

b) A B

c) B B

d) An exception is thrown

13. What is the range of values that random.random() can return?

a) [0.0, 1.0]

b) (0.0, 1.0]

c) (0.0, 1.0)

d) [0.0, 1.0)

14. Which operator is overloaded by invert()?

a) !

b) ~

c) ^

d) -

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

class A:

def init(self, x, y):

self.x = x

self.y = y

def str(self):

return 1

def eq(self, other):

return self.x * self.y == other.x * other.y

obj1 = A(5, 2)

obj2 = A(2, 5)

print(obj1 == obj2)

a) False

b) 1

c) True

d) An exception is thrown

16. To include the use of functions which are present in the random library, we must use the option:

a) import random

b) random.h

c) import.random

d) random.random

17. What will be the output of the following Python code snippet?

test = {1:'A', 2:'B', 3:'C'}

test = {}

print(len(test))

a) 0

b) None

c) 3

d) An exception is thrown

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

class stud:

def init(self, roll_no, grade):

self.roll_no = roll_no

self.grade = grade

def display (self):

print("Roll no : ", self.roll_no,", Grade: ", self.grade)

stud1 = stud(34, 'S')

stud1.age=7

print(hasattr(stud1, 'age'))

a) Error as age isn't defined

b) True

c) False

d) 7

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

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions

Question

3. How is relationship marketing related to branding?

Answered: 1 week ago