wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Test7

Total questions: 30

Worksheet time: 30mins

Name
Class
Date
1.

What is the default behavior of open('file.txt')?

a)

Open for reading

b)

Create new file

c)

Open in binary mode

d)

Append to file

2.

What happens if you try to read a file opened with 'w' mode?

a)

Reads normally

b)

Raises UnsupportedOperation

c)

Returns empty string

d)

Appends content

3.

Which of the following correctly opens a .csv file for reading with csv.reader?

a)

open('data.csv')

b)

open('data.csv', 'r')

c)

csv.reader('data.csv')

d)

csv.reader(open('data.csv'))

4.

In csv.reader, what is the type of each row returned in the loop?

a)

List

b)

Tuple

c)

String

d)

Dictionary

5.

What happens if csv.writer is used with a file not opened in text mode?

a)

Works fine

b)

Raises an error

c)

Writes binary output

d)

Automatically converts mode

6.

What is required to draw a rectangle in pygame?

a)

pygame.draw.rect(screen, color, rect)

b)

pygame.rectangle(...)

c)

pygame.render.rect(...)

d)

ygame.screen.draw(...)

7.

Which function updates the screen in pygame?

b)

pygame.update()

c)

pygame.display.update()

d)

pygame.draw()

8.

Which of the following are valid pygame event types?

a)

KEYDOWN

b)

QUIT

c)

EXIT

d)

MOUSEMOVE

9.

In matplotlib, what does plt.plot([1, 2], [3, 4]) do?

a)

Plots a bar chart

b)

Plots line from (1,3) to (2,4)

c)

Shows a scatter plot

d)

Raises an exception

10.

What function is used to label the x-axis in matplotlib?

a)

plt.xlabel()

b)

plt.set_xlabel()

c)

plt.labelx()

d)

plt.xtitle()

11.

Which of the following display a matplotlib plot?

b)

plt.render()

c)

plt.display()

d)

plt.plot()

12.

In pandas, what does df.head(3) return?

a)

Last 3 rows

b)

First 3 rows

c)

3 random rows

d)

First 3 columns

13.

Which data structure does pandas.read_csv() return?

a)

Series

b)

List

c)

DataFrame

d)

Numpy array

14.

Which method drops missing values in a DataFrame?

a)

drop()

b)

fillna()

c)

dropna()

d)

delete_na()

15.

Which is a valid way to select a column called 'age' in df?

a)

df.age

b)

df['age']

c)

df.get('age')

d)

df[age]

16.

What is the output of df.mean() if df contains both numeric and string columns?

a)

Mean of all columns

b)

Error

c)

Mean of numeric columns only

d)

Mean of string columns only

17.

What is the difference between Series and DataFrame?

a)

Series is 1D, DataFrame is 2D

b)

DataFrame holds multiple Series

c)

Series can’t have columns

d)

All of the above

18.

Which of the following create a NumPy array?

a)

np.array([1,2,3])

b)

np.new_array([1,2,3])

c)

numpy.array([1,2,3])

d)

np.list([1,2,3])

19.

What does np.zeros((2, 3)) return?

a)

A list of 2 zeros

b)

A 2x3 matrix of zeros

c)

An error

d)

A 2x3 identity matrix

20.

What is the result of np.arange(1, 6, 2)?

a)

[1,2,3,4,5,6]

b)

[1,3,5]

c)

[1,6,2]

d)

[1,2,4,6]

21.

What does np.dot(a, b) compute when a and b are 1D arrays?

a)

Matrix multiplication

b)

Element-wise product

c)

Scalar (dot product)

d)

Raises exception

22.

Which statement about NumPy broadcasting is TRUE?

a)

Works only on same-size arrays

b)

Allows operations on mismatched shapes

c)

Requires reshaping

d)

Is slower than loops

23.

Which method in pandas allows applying a function row-wise?

a)
b)

df.apply()

c)

df.iterrows()

d)

df.row()

24.

What is df.loc[0] used for?

a)

Select column named 0

b)

Select first row by label

c)

Select row by index

d)

Select column by position

25.

What is the output type of df['col1']?

a)

List

b)

Series

c)

DataFrame

d)

Array

26.

What happens if you try to plot in matplotlib without plt.show() in a script?

a)

Graph is saved automatically

b)

Graph shows by default

c)

Graph doesn’t appear

d)

Raises an error

27.

What function sets the window size in pygame?

a)

pygame.set_mode(size)

b)

pygame.display.set_mode(size)

c)

pygame.window.set(size)

d)

pygame.resize(size)

28.

What is np.reshape(np.arange(6), (2, 3)).shape?

a)

(3, 2)

b)

(2, 3)

c)

(6,)

d)

Error

29.

Which of the following combinations are valid ways to read a CSV and convert to NumPy?

a)

pd.read_csv(...).values

b)

np.loadtxt('file.csv', delimiter=',')

c)
d)

csv.reader(...).to_numpy()

30.

What happens when calling read() on a file opened in write-only mode ('w')?

a)

Reads the file

b)

Returns an empty string

c)

Raises io.UnsupportedOperation

d)

Skips the call