Now that you’re aware of what runtime errors are and how to use try and except to let your program cope with them without crashing, it’d be a good idea to go back to some of your previous python projects to make them more robust.
- Adapt this program which calculates some stats about how much you use your smartphone to make it more robust.
First, test the code to see what input you can put in which would make it crash. Then use
exceptto give the user a friendly error message instead of crashing.
- Adapt this program which calculates how old you’ll be at any point in the future to make it more robust
There’s some syntax errors to debug first before you can think about dealing with the runtime errors with
- Write a take-away meal price splitter program which asks you how much a meal costs and how many people are going to share it. It will then work out how much each person has to pay.
Remember that converting user input to a number is a time when you need to be careful about runtime errors. Use
exceptto make your code more robust