Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Q: Please answer each You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise). You need

Q:

Please answer each

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 and mcq explanation needed. Please don't copy from anywhere

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

d1 = {"john":40, "peter":45}

d2 = {"john":466, "peter":45}

d1 > d2

a) True

b) False

c) Error

d) None

2. What is the value of x if x = math.sqrt(4)?

a) 2

b) 2.0

c) (2, -2)

d) (2.0, -2.0)

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

import re

re.ASCII

a) 8

b) 32

c) 64

d) 256

4. How do you rename a file?

a) fp.name = 'new_name.txt'

b) os.rename(existing_name, new_name)

c) os.rename(fp, new_name)

d) os.set_name(existing_name, new_name)

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

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

print(a.get(1,4))

a) 1

b) A

c) 4

d) Invalid syntax for get method

6. Which of the following functions does not necessarily accept only iterables as arguments?

a) enumerate()

b) all()

c) chr()

d) max()

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

re.findall("hello world", "hello", 1)

a) ["hello"]

b) [ ]

c) hello

d) hello world

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

import turtle

t=turtle.Pen()

t.goto(300,9)

t.position()

a) 300.00, 9.00

b) 9, 300

c) 300, 9

d) 9.00, 300.00

9. Which of these is false about a package?

a) A package can have subfolders and modules

b) Each import package need not introduce a namespace

c) import folder.subfolder.mod1 imports packages

d) from folder.subfolder.mod1 import objects imports packages

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

import turtle

t=turtle.Pen()

t.color(0,1,0)

t.begin_fill()

for i in range(0,4):

t.forward(100)

t.right(90)

a) A square filled in with the colour green

b) A square outlined with the colour green

c) Blank canvas

d) Error

11. Which of the following isn't true about dictionary keys?

a) More than one key isn't allowed

b) Keys must be immutable

c) Keys must be integers

d) When duplicate keys encountered, the last assignment wins

12. Which of the following is the use of function in python?

a) Functions are reusable pieces of programs

b) Functions don't provide better modularity for your application

c) you can't also createyour own functions

d) All of the mentioned

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

>>> a={i: i*i for i in range(6)}

>>> a

a) Dictionary comprehension doesn't exist

b) {0: 0, 1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6:36}

c) {0: 0, 1: 1, 4: 4, 9: 9, 16: 16, 25: 25}

d) {0: 0, 1: 1, 2: 4, 3: 9, 4: 16, 5: 25}

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

15. The function pow(x,y,z) is evaluated as:

a) (x**y)**z

b) (x**y) / z

c) (x**y) % z

d) (x**y)*z

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

l=[1, -2, -3, 4, 5]

def f1(x):

return x<2

m1=filter(f1, l)

print(list(m1))

a) [1, 4, 5 ]

b) Error

c) [-2, -3]

d) [1, -2, -3]

17. Which of the following Python code creates an empty class?

a)

class A:

return

b)

class A:

pass

c)

class A:

d) It is not possible to createan empty class

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

def display(b, n):

while n > 0:

print(b,end="")

n=n-1

display('z',3)

a) zzz

b) zz

c) An exception is executed

d) Infinite loop

19. The expression a{5} will match _____________ characters with the previous regular expression.

a) 5 or less

b) exactly 5

c) 5 or more

d) exactly 4

20. Which of the following functions clears the regular expression cache?

a) re.sub()

b) re.pos()

c) re.purge()

d) re.subn()

21. What will be the output of the following Python function (random module has already been imported)?

random.choice('sun')

a) sun

b) u

c) either s, u or n

d) error

22. To open a file c:\scores.txt for appending data, we use ____________

a) outfile = open("c:\\scores.txt", "a")

b) outfile = open("c:\\scores.txt", "rw")

c) outfile = open(file = "c:\scores.txt", "w")

d) outfile = open(file = "c:\\scores.txt", "w")

23. How do you close a file object (fp)?

a) close(fp)

b) fclose(fp)

c) fp.close()

d) fp.close()

24. In file handling, what does this terms means "r, a"?

a) read, append

b) append, read

c) write, append

d) none of the mentioned

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

x = 50

def func():

global x

print('x is', x)

x = 2

print('Changed global x to', x)

func()

print('Value of x is', x)

a)

x is 50

Changed global x to 2

Value of x is 50

b)

x is 50

Changed global x to 2

Value of x is 2

c)

x is 50

Changed global x to 50

Value of x is 50

d) None of the mentioned

26. Can one block of except statements handle multiple exception?

a) yes, like except TypeError, SyntaxError [,...]

b) yes, like except [TypeError, SyntaxError]

c) no

d) none of the mentioned

27. What is the value of x if x = math.factorial(0)?

a) 0

b) 1

c) error

d) none of the mentioned

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

a={}

a[2]=1

a[1]=[2,3,4]

print(a[1][1])

a) [2,3,4]

b) 3

c) 2

d) An exception is thrown

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

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

def f1(a,b=[]):

b.append(a)

return b

print(f1(2,[3,4]))

a) [3,2,4]

b) [2,3,4]

c) Error

d) [3,4,2]

31. What happens if the file is not found in the following Python code?

a=False

while not a:

try:

f_n = input("Enter file name")

i_f = open(f_n, 'r')

except:

print("Input file not found")

a) No error

b) Assertion error

c) Input output error

d) Name error

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

x = [12, 34]

print(len(list(map(int, x))))

a) 2

b) 1

c) error

d) none of the mentioned

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

Unity From Zero To Proficiency Beginner A Step By Step Guide To Coding Your First Game

Authors: Patrick Felicia

1st Edition

1091872023, 978-1091872028

More Books

Students also viewed these Programming questions