WorksheetsTest7
Total questions: 30
Worksheet time: 30mins
What is the default behavior of open('file.txt')?
Open for reading
Create new file
Open in binary mode
Append to file
What happens if you try to read a file opened with 'w' mode?
Reads normally
Raises UnsupportedOperation
Returns empty string
Appends content
Which of the following correctly opens a .csv file for reading with csv.reader?
open('data.csv')
open('data.csv', 'r')
csv.reader('data.csv')
csv.reader(open('data.csv'))
In csv.reader, what is the type of each row returned in the loop?
List
Tuple
String
Dictionary
What happens if csv.writer is used with a file not opened in text mode?
Works fine
Raises an error
Writes binary output
Automatically converts mode
What is required to draw a rectangle in pygame?
pygame.draw.rect(screen, color, rect)
pygame.rectangle(...)
pygame.render.rect(...)
ygame.screen.draw(...)
Which function updates the screen in pygame?
Which of the following are valid pygame event types?
KEYDOWN
QUIT
EXIT
MOUSEMOVE
In matplotlib, what does plt.plot([1, 2], [3, 4]) do?
Plots a bar chart
Plots line from (1,3) to (2,4)
Shows a scatter plot
Raises an exception
What function is used to label the x-axis in matplotlib?
plt.xlabel()
plt.set_xlabel()
plt.labelx()
plt.xtitle()
Which of the following display a matplotlib plot?
In pandas, what does df.head(3) return?
Last 3 rows
First 3 rows
3 random rows
First 3 columns
Which data structure does pandas.read_csv() return?
Series
List
DataFrame
Numpy array
Which method drops missing values in a DataFrame?
drop()
fillna()
dropna()
delete_na()
Which is a valid way to select a column called 'age' in df?
df.age
df['age']
df.get('age')
df[age]
What is the output of df.mean() if df contains both numeric and string columns?
Mean of all columns
Error
Mean of numeric columns only
Mean of string columns only
What is the difference between Series and DataFrame?
Series is 1D, DataFrame is 2D
DataFrame holds multiple Series
Series can’t have columns
All of the above
Which of the following create a NumPy array?
What does np.zeros((2, 3)) return?
A list of 2 zeros
A 2x3 matrix of zeros
An error
A 2x3 identity matrix
What is the result of np.arange(1, 6, 2)?
[1,2,3,4,5,6]
[1,3,5]
[1,6,2]
[1,2,4,6]
What does np.dot(a, b) compute when a and b are 1D arrays?
Matrix multiplication
Element-wise product
Scalar (dot product)
Raises exception
Which statement about NumPy broadcasting is TRUE?
Works only on same-size arrays
Allows operations on mismatched shapes
Requires reshaping
Is slower than loops
Which method in pandas allows applying a function row-wise?
What is df.loc[0] used for?
Select column named 0
Select first row by label
Select row by index
Select column by position
What is the output type of df['col1']?
List
Series
DataFrame
Array
What happens if you try to plot in matplotlib without plt.show() in a script?
Graph is saved automatically
Graph shows by default
Graph doesn’t appear
Raises an error
What function sets the window size in pygame?
pygame.set_mode(size)
pygame.display.set_mode(size)
pygame.window.set(size)
pygame.resize(size)
What is np.reshape(np.arange(6), (2, 3)).shape?
(3, 2)
(2, 3)
(6,)
Error
Which of the following combinations are valid ways to read a CSV and convert to NumPy?
pd.read_csv(...).values
np.loadtxt('file.csv', delimiter=',')
pd.DataFrame.to_numpy()
csv.reader(...).to_numpy()
What happens when calling read() on a file opened in write-only mode ('w')?
Reads the file
Returns an empty string
Raises io.UnsupportedOperation
Skips the call
