Step 9 – Extension activities
Hopefully your program works.
There are a number of things we could do to extend the program.
- Get the program to run in a loop. This is quite each to do but involves changing lots of indents.
- 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
- add a third (or fourth) number – but how would you deal with division?
- 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.