Arithmetic operations in Python
Python gives seven arithmetic operations: addition +, subtraction -, multiplication *, division /, the whole part of a quotient //, the remainder % and the power **. For example 17 / 5 = 3.4 (always a float), 17 // 5 = 3 and 17 % 5 = 2, 2 ** 5 = 32. In an expression the power is done first, then *, /, //, % (left to right), and + and - last; brackets change the order. When writing a fraction put the numerator and the denominator in separate brackets, for example (a**2 + b**2) / (a + b); if the brackets are forgotten the result is different. To increase a variable you can write the short x += y instead of x = x + y; -=, *=, /=, //=, %=, **= work the same way. With // and % the digits of a number can be separated: for a three-digit x, x // 100 is the first digit, x // 10 % 10 is the middle digit and x % 10 is the last.
“Find the result”: the teacher writes 6 expressions on the board (for example 2 + 3 * 4, (2 + 3) * 4, 20 // 6, 20 % 6, 2 ** 3 ** 1, 9 / 3). Groups first work them out by hand, then check in IDLE and explain any difference.