Arithmetic Operators - Interactive exercises#

Make sure you are running this in Colab!

Everything in a notebook is in cells. Text like what you’re reading right now goes in a ‘Markdown’ cell. Code goes in a code cell, like the one below. Try doing a simple math calculation like \(2+2\), and push Shift+Enter or click ‘Run’ in the top bar to evaluate it.

Now try multiplying, dividing, subtraction. When you evaluate a Python command in a code cell, the result is printed below the cell. You can put multiple lines in a cell by using Enter between them. When you evaluate the cell, the output is only the last value calculated. Try it.

Most math expressions are straightforward. One slightly unusual thing is the power operator. We code \(x^y\) as x**y. Try using this to:

  1. Find \(2^{10}\).

  2. Find the square root of a million.

  3. Find the cube root of \(4913\).

The standard division operator is /, for instance \(1/4 = 0.25\). There is also the integer division operator // and the remainder operator % which are described above.

Exercise Try a few things like 7//3 and 7%3 to see how they work.

Exercise Demonstrate how these operators (or just one of them!) can be used to quickly evaluate if a number is even or odd

WARNING we will be using // and % for problems in the coming weeks, and will require you to identify when to use them. Still confused about what these do? Ask one of us!