Check what you picked up from the Math reading: answer each question, then press Check. Nothing here is graded.

Question 1

Put these operators in order of their precedence (what order they are evaluated):

Drag the items into order, or use the arrow buttons, then check.

  1. Parentheses
  2. Exponents
  3. Multiplication, Modulo, and Division
  4. Addition, Subtraction

Python evaluates parentheses first, then exponents (**), then multiplication, division and modulo (*, /, //, %) from left to right, then addition and subtraction from left to right.

Question 2

Predict the result of this expression: 4 + 5 * 2

Show worked solution

Multiplication comes before addition, so Python first computes 5 * 2, which is 10. Then 4 + 10 gives 14.

Question 3

Predict the result of this expression: 10 / 5 - 1

Show worked solution

Division comes before subtraction. 10 / 5 is float division, which always gives a float: 2.0. Then 2.0 - 1 is 1.0, so Python shows 1.0, not 1.

Question 4

Predict the result of this expression: 10 // 5 - 1

Show worked solution

Division comes before subtraction. 10 // 5 is integer division of two integers, which gives the integer 2. Then 2 - 1 is 1: every value involved is an integer, so the result is 1, not 1.0.

Question 5

Predict the result of this expression: (10+8) % 12

Show worked solution

Parentheses come first: 10+8 is 18. Then 18 % 12 is the remainder after dividing 18 by 12: 12 fits into 18 once, with 6 left over. On a clock, 18 o'clock is 6pm.

Question 6

How many things can be added at once with the "+" operator?

Select one answer, then check.

  • Not quite. Adding is one of the things computers are best at: they do billions of calculations per second.
  • Correct. Each + adds the two values on either side of it, its operands. You can write several in a row, but 2 + 3 + 4 is two additions: Python first adds 2 and 3, then adds 4 to the resulting 5.
  • Not quite. You can write as many + operators in a row as you like, but each one still adds only two values: 2 + 3 + 4 first adds 2 and 3, then adds 4 to the resulting 5, giving 9.

Question 7

What is the result if you ask Python to perform the following computation? "2"+2

Select one answer, then check.

  • Not quite. You would get "22" by adding two strings, "2" + "2". Python won't turn the integer 2 into a string for you.
  • Not quite. You would get 4 by adding two integers, 2 + 2. Python won't treat the string "2" as a number for you.
  • Not quite. Python converts neither value, so it can't do the math and hand back a string either.
  • Correct. "2" is a string and 2 is an integer, and Python refuses to guess whether you meant text or a number. It stops with an error: TypeError: can only concatenate str (not "int") to str.