Chapter 0 quiz
Basics of Python
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 13.0 -3.0 13 -4 13.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 β
numsis 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;
gradeends as"A" - A
SyntaxErrorβ thresholds must be increasing
Question 4
def show(x): print(x) then r = show(5). What is r?
5None"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 numpyon every restartnp = 0
Question 6
What does print(0.1 + 0.2 == 0.3) print?
TrueFalse- 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 TrueTrue False TrueFalse False TrueTrue 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)