Chapter 0 quiz

Basics of Python

0 of 10 answered

These questions review the examples in the companion slides. Choose an answer, then check the explanation.

Question 1

What does print(10 // 3, -10 // 3, 10 % 3) print?

  • 3 -3 1
  • 3.0 -3.0 1
  • 3 -4 1
  • 3.33 -3.33 1

Question 2

nums = [10, 20, 30, 40]; alias = nums; alias.append(50). What is nums now?

  • [10, 20, 30, 40]
  • It raises an error β€” nums is protected
  • [10, 20, 30, 40, 50]
  • [50, 10, 20, 30, 40]

Question 3

score = 95. if score >= 60: grade = β€œC” then elif score >= 90: grade = β€œA”. What is grade?

  • "C" β€” the first true branch wins
  • "A" β€” the best matching branch wins
  • Both run; grade ends as "A"
  • A SyntaxError β€” thresholds must be increasing

Question 4

def show(x): print(x) then r = show(5). What is r?

  • 5
  • None
  • "5"
  • A TypeError

Question 5

NumPy is installed, but a freshly restarted kernel reports NameError: np is not defined. What should you run first?

  • import numpy as np
  • %pip install numpy on every restart
  • np = 0

Question 6

What does print(0.1 + 0.2 == 0.3) print?

  • True
  • False
  • It raises a TypeError
  • 0.3

Question 7

nums = [10, 20, 30, 40]; alias = nums; fresh = [10, 20, 30, 40]. What do nums == fresh, nums is fresh, alias is nums give?

  • True True True
  • True False True
  • False False True
  • True False False

Question 8

What does list(range(1, 5)) return?

  • [1, 2, 3, 4, 5]
  • [1, 2, 3, 4]
  • [0, 1, 2, 3, 4]
  • [1, 5]

Question 9

def add_city(c, cities=[]): cities.append(c); return cities. After add_city(β€œNYC”), what does add_city(β€œLA”) return?

  • ["LA"]
  • []
  • ["NYC", "LA"]
  • A TypeError

Question 10

In a fresh session, you run from math import sqrt as root. Which call matches that import?

  • math.sqrt(144)
  • sqrt(144)
  • root(144)