Check your understanding of the previous reading: sequential execution, statements and expressions.

Question 1

True or false: normally, statements are executed from top to bottom.

Select one answer, then check.

  • Correct. A program runs its statements one after another, starting at the first line and moving down, just like reading down the page of a book. Later you will meet statements that change this flow, but top to bottom is the default.
  • Not quite. Python runs the statements of a program in order, from the top line down to the bottom one.

Question 2

True or false: expressions are evaluated from left to right.

Select one answer, then check.

  • Correct. Python works through an expression from left to right. Operator precedence still decides which operation goes first: in 2 + 3 * 4 the multiplication is done before the addition, so the result is 14, not 20. Among operators with the same precedence, the leftmost one goes first: 10 - 4 - 3 is 3.
  • Not quite. Python does evaluate an expression from left to right. What can look like an exception is operator precedence: in 2 + 3 * 4 the multiplication is done first, just like in math, but Python still reads the values 2, 3 and 4 from left to right.

Question 3

True or false: programs may execute very quickly in computers, but they always happen one step at a time.

Select one answer, then check.

  • Correct. Even when a whole program finishes in a few milliseconds, the computer still runs it one statement after another. Execution happens over time, not all at once.
  • Not quite. However fast a program runs, it doesn't happen all at once: each statement takes its own small amount of time, one step after the other.

Question 4

Which of the following can be involved in an expression?

Select every correct answer, then check.

  • Correct. Any value, such as 5, 10.0, True or "Hello", is an expression on its own.
  • Correct. Math operations such as 1 + 2 and 8 / 4 combine values into a new value.
  • Correct. Expressions can be made up of expressions: in (1 + 5) > age, both 1 + 5 and age are expressions themselves.
  • Correct. Comparison operators such as > and ==, and boolean operators such as and, or and not, combine values into True or False. The reading's 5 > 4 and False or not True are expressions.
  • Not quite. It's the other way around: a statement, such as an assignment or a print, can contain expressions, but a statement is never part of an expression.
  • Correct. A variable such as age or score is an expression: it stands for the value stored in it.

Question 5

Evaluate each expression and identify the type of the result.
(1 + 2) * 4 / 3
1 + 2 + 3 + 4 + 5
(1 + 2) > 4
"Hello " + "World"
4 > 5 or 5 == 6