The Python Calculator

Step 9 – Extension activities

Hopefully your program works.

There are a number of things we could do to extend the program.

  1. Get the program to run in a loop. This is quite each to do but involves changing lots of indents.

  2. Python has two clever division tricks it can do:
    • remainder division. This gives the remainder when you divide two numbers (so 7 divided by 3 would give 1 – because the remainder is 1). The way python does this is number1 % number2
    • integer division. This gives the whole number, not the remainder (so 7 divided by 3 would give 2, as the answer is 2 remainder 1). In Python you do this using number1 // number2
    Try adding both of these to your program.
  3. add a third (or fourth) number – but how would you deal with division?
  4. if the user doesn't enter a number at all (just press Enter or enter a letter) the program will crash. There's a way of dealing with this using Try–Except. This is tricky, but I have a page that will show you how it works – click here to go there

Test everything really carefully to make sure it works.