Lesson 1-9 · Variables & Expressions — Knowledge ChecksAnswer key
What is the difference between = in math and = in Python?
Math's = states that two things are equal. Python's = does something: it works out the right-hand side and stores that result in the variable named on the left.
After these three lines, what is total?
total = 10 total = total + 5 total = total + 5
Each line reads what is currently in total, works out the right side with it, and stores the result back: 10, then 10+5 = 15, then 15+5 = 20.
In the line reflectance = Reflectance.get_default_reflectance() what is the difference between the two spellings?
Python is case-sensitive, and the convention is Capitalized for classes, lowercase snake_case for your own variables. Both names are needed and they mean different things.
What is the value of 10 + 4 * 2 ?
Multiplication goes before addition: 4 * 2 = 8 first, then 10 + 8 = 18. To get 28 you would need parentheses: (10 + 4) * 2.
Your white reading is 0.2 and your black reading is 0.8, and you want the midpoint (0.5). Which line gives it?
Without parentheses, only black is divided: 0.2 + 0.4 = 0.6 — not the midpoint. The parentheses force the addition first: (0.2 + 0.8) / 2 = 0.5.