Arithmetic operators
Q1. Predict the answers to the following questions. Some symbols may be unfamiliar to you. Use the Internet to find out what they are:
Questions | Answers |
3 + 20 | |
10 + 2 * 2 | |
5 + 20 / 5 | |
10 / 2 - 1 | |
2 ** 3 | |
3*1**3 | |
2 ** 1 + 2 | |
12 / 8 | |
12 // 8 | |
20 // 3 | |
20 // 40 | |
10 % 3 | |
8 % 12 | |
5 % 5 | |
(2 + 1) * 2 | |
3 * (3 - 1) | |
10.0 / 5.0 | |
10 / 5 | |
10 / 0 | |
'23'+'3' | |
5*'spam' | |
6*eggs |
Q2. When you have predicted as many of the answers as you can, compare your answers to a friend's. Then try them out in the Python shell. How many did you get correct?
Q3. Here is a mixed-up list of maths operators. Put them in order of precedence, from highest to lowest. In other words, which operators should you do first and which ones last, if you have more than one opeator in an equation? Some operators have equal precedence. You should show this in your answer.
Mixed-up list | Correct order of precedence - High to Low |
multiplication | |
MOD | |
powers | |
brackets | |
minus | |
division | |
add | |
integer division |
Q4. Compare your table to a friend's table. Are they the same? Use the Internet to check your answers. Search for operator precedence in Python 3.