Level 1 — RecognitionPython & Scientific Computing

Python & Scientific Computing

20 minutes30 marksprintable — key stays hidden on paper

Chapter: 1.4 Python & Scientific Computing Level: 1 — Recognition (MCQ + Matching + True/False with justification) Time Limit: 20 minutes Total Marks: 30


Section A — Multiple Choice (1 mark each) — 10 marks

Choose the single best answer.

Q1. What is the data type of 3 / 2 in Python 3?

  • (a) int
  • (b) float
  • (c) str
  • (d) complex

Q2. Which expression correctly builds a list of squares of even numbers from 0 to 9 using a comprehension?

  • (a) [x**2 for x in range(10) if x % 2 == 0]
  • (b) [x^2 for x in range(10) if x / 2 == 0]
  • (c) {x**2 for x in range(10) if x % 2}
  • (d) (x**2 for x in range(10))

Q3. Given a = np.array([1, 2, 3]) and b = np.array([[10], [20]]), what is the shape of a + b?

  • (a) (3,)
  • (b) (2, 1)
  • (c) (2, 3)
  • (d) Error — shapes incompatible

Q4. Which pandas method reads a comma-separated file into a DataFrame?

  • (a) pd.load_csv()
  • (b) pd.read_csv()
  • (c) pd.open_csv()
  • (d) pd.from_csv()

Q5. Which keyword turns a function into a generator?

  • (a) return
  • (b) async
  • (c) yield
  • (d) lambda

Q6. What does arr.shape return for arr = np.zeros((4, 5))?

  • (a) 20
  • (b) (4, 5)
  • (c) (5, 4)
  • (d) [4, 5]

Q7. Which Git command stages all modified files for the next commit?

  • (a) git commit -a
  • (b) git push
  • (c) git add .
  • (d) git status

Q8. In a Jupyter notebook, which shortcut runs the current cell and moves to the next?

  • (a) Ctrl + Enter
  • (b) Shift + Enter
  • (c) Alt + Enter
  • (d) Esc

Q9. Which command creates a Python virtual environment named env using the built-in module?

  • (a) pip install env
  • (b) python -m venv env
  • (c) conda new env
  • (d) virtual env

Q10. Vectorized NumPy operations are generally preferred over Python for loops because they:

  • (a) always use less memory
  • (b) execute the loop in optimized C code, improving speed
  • (c) change the result mathematically
  • (d) are the only way to add arrays

Section B — Matching (1 mark each) — 8 marks

Match each item in Column X to the correct item in Column Y. Write pairs like Q11 → (iii).

Column X Column Y
Q11. pd.Series (i) 2-D labelled table
Q12. pd.DataFrame (ii) create isolated dependency environment
Q13. plt.plot() (iii) 1-D labelled array
Q14. seaborn.heatmap() (iv) draw a line chart
Q15. conda create (v) visualize a matrix with colour intensity
Column X Column Y
Q16. .json file (vi) reads help/docstring of an object
Q17. .parquet file (vii) key–value / nested text data format
Q18. help(obj) (viii) columnar binary storage format

Section C — True/False with justification (2 marks each: 1 answer + 1 justification) — 12 marks

State True or False and give a one-line justification.

Q19. In NumPy broadcasting, arrays of shape (3, 1) and (1, 4) can be added to produce a (3, 4) array.

Q20. A Python tuple is mutable, so you can reassign one of its elements in place.

Q21. git commit uploads your local commits to the remote repository on GitHub.

Q22. A generator expression (x for x in range(1000000)) stores all one million values in memory immediately.

Q23. In Python, if, for, and while blocks are defined by indentation rather than braces {}.

Q24. df.head() by default returns the first 10 rows of a DataFrame.

Answer keyMark scheme & solutions

Section A — MCQ (1 mark each)

Q1 → (b) float. True division / always yields a float in Python 3; 3/2 = 1.5. (1)

Q2 → (a). x**2 is exponentiation (^ is bitwise XOR), and if x % 2 == 0 selects evens; option (c) uses {} (set) and wrong filter, (d) is a generator. (1)

Q3 → (c) (2, 3). a has shape (3,) → broadcast to (1,3); b is (2,1). Broadcasting stretches to (2,3). (1)

Q4 → (b) pd.read_csv(). Standard pandas CSV reader. (1)

Q5 → (c) yield. A function containing yield returns a generator that produces values lazily. (1)

Q6 → (b) (4, 5). .shape returns a tuple of dimensions matching the constructor. (1)

Q7 → (c) git add .. Stages all changes in the current directory. (git commit -a stages+commits only already-tracked files.) (1)

Q8 → (b) Shift + Enter. Runs cell and advances; Ctrl+Enter runs but stays. (1)

Q9 → (b) python -m venv env. venv is the built-in module for virtual environments. (1)

Q10 → (b). NumPy pushes the loop into compiled C, avoiding Python interpreter overhead → faster. Results are identical. (1)

Section B — Matching (1 mark each)

  • Q11 → (iii) Series = 1-D labelled array. (1)
  • Q12 → (i) DataFrame = 2-D labelled table. (1)
  • Q13 → (iv) plt.plot() draws a line chart. (1)
  • Q14 → (v) heatmap() shows matrix values as colour intensity. (1)
  • Q15 → (ii) conda create makes an isolated environment. (1)
  • Q16 → (vii) JSON is a key–value/nested text format. (1)
  • Q17 → (viii) Parquet is a columnar binary storage format. (1)
  • Q18 → (vi) help(obj) prints the docstring/help. (1)

Section C — True/False with justification (1 + 1 each)

Q19 — True. (1) Dimensions are compatible when equal or one is 1; (3,1)&(1,4) broadcast to (3,4). (1)

Q20 — False. (1) Tuples are immutable; element assignment raises TypeError. (1)

Q21 — False. (1) git commit records locally; git push uploads to the remote. (1)

Q22 — False. (1) Generators are lazy — they yield one value at a time and hold ~constant memory. (1)

Q23 — True. (1) Python uses indentation to delimit code blocks, not braces. (1)

Q24 — False. (1) df.head() returns the first 5 rows by default. (1)

[
  {"claim":"3/2 evaluates to float 1.5","code":"result = (type(3/2).__name__=='float') and (3/2==1.5)"},
  {"claim":"Broadcasting (3,1)+(1,4) -> (3,4)","code":"import numpy as np; result = (np.zeros((3,1))+np.zeros((1,4))).shape==(3,4)"},
  {"claim":"a=(3,) + b=(2,1) broadcasts to (2,3)","code":"import numpy as np; a=np.array([1,2,3]); b=np.array([[10],[20]]); result=(a+b).shape==(2,3)"},
  {"claim":"Even squares comprehension gives [0,4,16,36,64]","code":"result=[x**2 for x in range(10) if x%2==0]==[0,4,16,36,64]"},
  {"claim":"Tuple element assignment raises TypeError (immutable)","code":"t=(1,2,3); err=False\ntry:\n    t[0]=9\nexcept TypeError:\n    err=True\nresult=err"}
]