Skip to content

Module 4 Graded Quiz: Working with Data in Python:Python for Data Science, AI & Development (Applied Data Science Specialization) Answers 2025

1. NumPy & Pandas Assessment — Answers in Your Format


Q1. np.dot(a, b)

Correct Answer:
1 — Dot product = (-1×1) + (1×1) = 0 + 1 = 1

❌ array([0,2]) — Not a dot product result
❌ array([[-1,-1],[1,1]]) — This is outer product–like
❌ 0 — Incorrect sum


Q2. First step before matrix multiplication

Correct Answer:
The number of columns in A must equal the number of rows in B.

❌ Both arrays must be square — Not required
❌ Sum of dimensions even — Irrelevant
❌ Same shape — Only for elementwise multiply


Q3. X.ndim

Correct Answer:
2 — The array has 2 dimensions (2×3)

❌ 6 — Not dimension
❌ 3 — Not shape length
❌ 5 — No relation


Q4. Multiply NumPy array by scalar

Correct Answer:
Each element in the array is multiplied by the scalar value

❌ Only first row multiplied — Wrong
❌ Scalar becomes new dimension — Wrong
❌ Only diagonal multiplied — Wrong


Q5. file.readline()

Correct Answer:
This is line 1

❌ Empty — Only if file empty
❌ All lines — that’s read()
❌ “This” — Wrong slicing


Q6. Advantage of “with” statement

Correct Answer:
It automatically closes the file when the code block is exited.

❌ Improves speed — Not the reason
❌ Allows writing regardless of permissions — Wrong
❌ Makes file read-only — Wrong


Q7. Using “w” mode on existing file

Correct Answer:
The file’s previous contents are erased and replaced with the new content.

❌ Raises error — Wrong
❌ Unchanged — Wrong
❌ Appends — That’s “a”, not “w”


Q8. Difference between “w” and “a”

Correct Answer:
“w” overwrites the file while “a” adds to the end of the file

❌ Binary vs text — Wrong
❌ Faster/slower — Not relevant
❌ Creates new vs modifies — Incorrect


Q9. loc vs iloc

Correct Answer:
loc uses labels for indexing, while iloc uses integer positions

❌ loc rows, iloc columns — Wrong
❌ loc faster — No
❌ loc only single cells — False


Q10. Create DataFrame from dictionary

Correct Answer:
pd.DataFrame(dictionary)

❌ pd.dict_to_df — Not valid
❌ pd.from_dict — Exists, but not the best answer here
❌ pd.create_dataframe — Invalid


🧾 Summary Table

Q Correct Answer
1 1
2 Columns of A = Rows of B
3 2
4 Each element multiplied
5 “This is line 1”
6 Auto-closes file
7 Overwrites file
8 w = overwrite, a = append
9 loc = labels, iloc = positions
10 pd.DataFrame(dictionary)