Question: You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise). You need to do this in

You are given an n x n 2D matrix representing an image.

Rotate the image by 90 degrees (clockwise).

You need to do this in place.

Note that if you end up using an additional array, you will only receive partial score.

Example:

If the array is

[

[1, 2],

[3, 4]

]

Then the rotated array becomes:

[

[3, 1],

[4, 2]

]

Python code for above cp question and mcq questions explanation is must. code will be tested on large test cases

1. What will be the output of the following Python function if the random module has already been imported?

random.randint(3.5,7)

a) Error

b) Any integer between 3.5 and 7, including 7

c) Any integer between 3.5 and 7, excluding 7

d) The integer closest to the mean of 3.5 and 7

2. ______________ returns a dictionary of the module namespace.

________________ returns a dictionary of the current namespace.

a)

locals()

globals()

b)

locals()

locals()

c)

globals()

locals()

d)

globals()

globals()

3. Lambda contains block of statements.

a) True

b) False

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

def foo():

try:

return 1

finally:

return 2

k = foo()

print(k)

a) 1

b) 2

c) 3

d) error, there is more than one return statement in a single try-finally block

5. Which of the following Python codes will result in an error?

object = 'a'

a) >>> pickle.dumps(object)

b) >>> pickle.dumps(object, 3)

c) >>> pickle.dumps(object, 3, True)

d) >>> pickle.dumps('a', 2)

6. The function used to alter the thickness of the pen to 'x' units:

a) turtle.width(x)

b) turtle.span(x)

c) turtle.girth(x)

d) turtle.thickness(x)

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

def foo(fname, val):

print(fname(val))

foo(max, [1, 2, 3])

foo(min, [1, 2, 3])

a) 3 1

b) 1 3

c) error

d) none of the mentioned

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

l=[n for n in range(5)]

f=lambda x:bool(x%2)

print(f(3), f(1))

for i in range(len(l)):

if f(l[i]):

del l[i]

print(i)

a)

True True

1

2

Error

b)

False False

1

2

c)

True False

1

2

Error

d)

False True

1

2

9. What is setattr() used for?

a) To access the attribute of the object

b) To set an attribute

c) To check if an attribute exists or not

d) To delete an attribute

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

min = (lambda x, y: x if x < y else y)

min(101*99, 102*98)

a) 9997

b) 9999

c) 9996

d) None of the mentioned

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

a={}

a['a']=1

a['b']=[2,3,4]

print(a)

a) Exception is thrown

b) {'b': [2], 'a': 1}

c) {'b': [2], 'a': [3]}

d) {'b': [2, 3, 4], 'a': 1}

12. 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

13. How do you get the name of a file from a file object (fp)?

a) fp.name

b) fp.file(name)

c) self.name(fp)

d) fp.name()

14. Is the following Python code correct?

>>> class A:

def init(self,b):

self.b=b

def display(self):

print(self.b)

>>> obj=A("Hello")

>>> del obj

a) True

b) False

15. The output of the following two Python codes are the same.

CODE 1

>>> re.split(r'(a)(t)', 'The night sky')

CODE 2

>>> re.split(r'\s+', 'The night sky')

a) True

b) False

16. What does the function re.match do?

a) matches a pattern at the start of the string

b) matches a pattern at any position in the string

c) such a function does not exist

d) none of the mentioned

17. What is the biggest reason for the use of polymorphism?

a) It allows the programmer to think at a more abstract level

b) There is less program code to write

c) The program will have a more elegant design and will be easier to maintain and update

d) Program code takes up less space

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!