wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

AI Course Quiz: Python, NumPy, Pandas, OpenCV

Total questions: 65

Worksheet time: 38mins

Name
Class
Date
1.

What will be the output of the following code?

a)

[1, 2, 3]

b)

[2, 3, 4]

c)

[2, 3]

d)

[1, 2, 3, 4]

2.

Which of the following is the correct way to handle exceptions in Python?

a)

try-catch

b)

try-except

c)

catch-finally

d)

handle-error

3.

What is the output of this code?

a)

[1] [2]

b)

[1] [1, 2]

c)

[1, 2] [1, 2]

d)

Error

4.

Which method is used to remove whitespace from both ends of a string?

a)

trim()

b)

strip()

c)

remove()

d)

clean()

5.

What will len("Hello\nWorld") return?

a)

10

b)

11

c)

12

d)

9

6.

Which of the following creates a dictionary comprehension correctly?

a)

{x: x**2 for x in range(5)}

b)

[x: x2 for x in range(5)]

c)

{x, x2 for x in range(5)}

d)

(x: x2 for x in range(5))

7.

What is the output of this code?

a)

"ef"

b)

"de"

c)

"cd"

d)

"f"

8.

Which function is used to get user input in Python 3?

a)

raw_input()

b)

input()

c)

get_input()

d)

read()

9.

What will be the result of bool([])?

a)

True

b)

False

c)

None

d)

Error

10.

Which of the following is NOT a valid variable name in Python?

a)

_variable

b)

variable2

c)

2variable

d)

variable_name

11.

What will be the shape of the resulting array?

a)

(3, 4, 2)

b)

(2, 4, 3)

c)

(12, 2)

d)

(24,)

12.

What is the output of this code?

a)

[4, 10, 18]

b)

32

c)

[[4, 5, 6], [8, 10, 12], [12, 15, 18]]

d)

Error

13.

Which function creates an array with evenly spaced values over a specified range?

a)

np.arange()

b)

np.linspace()

c)

np.logspace()

d)

All of the above

14.

What will np.array([1, 2, 3]).dtype return?

a)

int32 (or int64)

b)

float64

c)

object

d)

string

15.

What is the output of this code?

a)

[[1, 2], [3, 4]]

b)

[[1, 3], [2, 4]]

c)

[[4, 3], [2, 1]]

d)

Error

16.

Which function is used to change the shape of an array without changing its data?

a)

np.shape()

b)

np.resize()

c)

np.reshape()

d)

np.reform()

17.

What will be the output?

a)

[True, False, False, True, True]

b)

[4, 5]

c)

[3, 4]

d)

Error

18.

Which method returns the indices of maximum values along an axis?

a)

np.max()

b)

np.argmax()

c)

np.maximum()

d)

np.maxindex()

19.

What is the result of np.array([1, 2, 3]) + 5?

a)

[6, 7, 8]

b)

[1, 2, 3, 5]

c)

Error

d)

11

20.

Which function creates an identity matrix?

a)

np.identity()

b)

np.eye()

c)

Both a and b

d)

np.ones()

21.

What will np.array([1, 2, 3]).ndim return?

a)

0

b)

1

c)

2

d)

3

22.

Which function is used to concatenate arrays along an existing axis?

a)

np.stack()

b)

np.concatenate()

c)

np.append()

d)

All of the above

23.

What will be the output?

a)

1

b)

2

c)

3

d)

Error

24.

Which method is used to read a CSV file in pandas?

a)

pd.read_csv()

b)

pd.load_csv()

c)

pd.import_csv()

d)

pd.csv_read()

25.

What is the output of this code?

a)

(2, 3)

b)

(3, 2)

c)

(6,)

d)

Error

26.

Which method returns the first n rows of a DataFrame?

a)

df.first()

b)

df.head()

c)

df.top()

d)

df.start()

27.

What will be the result?

a)

4

b)

3

c)

1

d)

Error

28.

Which method is used to group DataFrame rows based on column values?

a)

df.group()

b)

df.groupby()

c)

df.aggregate()

d)

df.cluster()

29.

What is the output?

a)

1

b)

2

c)

3

d)

Error

30.

Which method is used to merge two DataFrames?

a)

df.merge()

b)

df.join()

c)

pd.merge()

d)

All of the above

31.

What will df.info() provide?

a)

Statistical summary

b)

Data types and memory usage

c)

First few rows

d)

Column names only

32.

Which method is used to apply a function to each element in a DataFrame?

a)

df.apply()

b)

df.map()

c)

df.applymap()

d)

Both a and c

33.

What is the output?

a)

1.0

b)

2.0

c)

3.0

d)

6.0

34.

Which method is used to reset the index of a DataFrame?

a)

df.reset_index()

b)

df.reindex()

c)

df.set_index()

d)

df.index_reset()

35.

Which function is used to read an image in OpenCV?

a)

cv2.load_image()

b)

cv2.imread()

c)

cv2.read_img()

d)

cv2.open_image()

36.

What does the flag cv2.IMREAD_GRAYSCALE do?

a)

Loads image in color

b)

Loads image in grayscale

c)

Loads image with alpha channel

d)

Loads image as binary

37.

Which function displays an image in OpenCV?

a)

cv2.show()

b)

cv2.display()

c)

cv2.imshow()

d)

cv2.view()

38.

What will be the shape of an RGB image loaded with OpenCV?

a)

(height, width, 3)

b)

(width, height, 3)

c)

(3, height, width)

d)

(height, width)

39.

Which function is used to convert color spaces in OpenCV?

a)

cv2.convert_color()

b)

cv2.cvtColor()

c)

cv2.change_color()

d)

cv2.color_convert()

40.

What does cv2.waitKey(0) do?

a)

Waits for any key press indefinitely

b)

Waits for 0 seconds

c)

Closes all windows

d)

Does nothing

41.

Which function is used to resize an image?

a)

cv2.resize()

b)

cv2.scale()

c)

cv2.size_change()

d)

cv2.reshape()

42.

What is the correct way to convert BGR to RGB?

a)

cv2.cvtColor(img, cv2.COLOR_BGR2RGB)

b)

cv2.cvtColor(img, cv2.COLOR_RGB2BGR)

c)

cv2.convert(img, 'RGB')

d)

img[:,:,::-1]

43.

Which function applies Gaussian blur to an image?

a)

cv2.blur()

b)

cv2.GaussianBlur()

c)

cv2.gaussian()

d)

cv2.smooth()

44.

What does cv2.destroyAllWindows() do?

a)

Closes the current window

b)

Closes all OpenCV windows

c)

Destroys the image

d)

Clears memory

45.

Which function creates a basic line plot?

a)

plt.line()

b)

plt.plot()

c)

plt.draw()

d)

plt.graph()

46.

What will this code create?

a)

Line plot

b)

Scatter plot

c)

Bar plot

d)

Histogram

47.

Which function adds a title to a plot?

a)

plt.title()

b)

plt.set_title()

c)

plt.add_title()

d)

plt.heading()

48.

What does plt.xlabel() do?

a)

Sets the x-axis label

b)

Sets the x-axis limits

c)

Sets the x-axis ticks

d)

Sets the x-axis scale

49.

Which function creates subplots?

a)

plt.subplot()

b)

plt.subplots()

c)

Both a and b

d)

plt.create_subplots()

50.

What does plt.legend() do?

a)

Creates a legend for the plot

b)

Sets the plot title

c)

Adds grid lines

d)

Changes plot colors

51.

Which function creates a histogram?

a)

plt.hist()

b)

plt.histogram()

c)

plt.bar()

d)

plt.frequency()

52.

What does plt.grid() do?

a)

Creates a new plot

b)

Adds grid lines to the plot

c)

Changes the plot background

d)

Sets plot boundaries

53.

What is the result of multiplying a 3×2 matrix with a 2×4 matrix?

a)

3×4 matrix

b)

2×2 matrix

c)

6×8 matrix

d)

Not possible

54.

What is the determinant of the identity matrix of size 3×3?

a)

0

b)

1

c)

3

d)

9

55.

Which property does NOT hold for matrix multiplication?

a)

Associative

b)

Commutative

c)

Distributive

d)

None of the above

56.

What is the transpose of matrix [[1, 2], [3, 4]]?

a)

[[1, 2], [3, 4]]

b)

[[1, 3], [2, 4]]

c)

[[4, 3], [2, 1]]

d)

[[2, 1], [4, 3]]

57.

What is the rank of a 4×4 identity matrix?

a)

0

b)

1

c)

4

d)

16

58.

Which operation finds the length (magnitude) of a vector?

a)

Dot product

b)

Cross product

c)

Norm

d)

Determinant

59.

What is the dot product of vectors [1, 2, 3] and [4, 5, 6]?

a)

[4, 10, 18]

b)

32

c)

14

d)

21

60.

An orthogonal matrix has which property?

a)

A × A^T = I

b)

A × A = I

c)

A^T = A

d)

det(A) = 0

61.

What will be the output of the following code:

a)

22

b)

44

c)

66

d)

88

62.

What will be the output of the following code:

a)

[5,7]

b)

[5,6]

c)

[6,8]

d)

Error

63.

What will be the output of the following code:

a)

(100, 100), 128

b)

(100, 100, 1), 128

c)

(100, 100), 114

d)

(100, 100), 132

64.

What will be the output of the following code:

a)

4, (2, 2), 14.0

b)

2, (2,), 14

c)

4, (2, 2), 14

d)

1, (2, 2), 8.6

65.

What will be the output of the following code:

a)

True

b)

False

c)

Error

d)

Depends on eigenvals