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
Page 1: Intro
Page 2: The theory: learn what you need to know as fast as possible.
Page 3: Try it: try out and adapt some working python code snippets.
Page 4: Debug it: Learn how to find and fix common mistakes.
Page 5: Extend it: Choose a project idea to use your newfound python skills.
For some reason when I save my code it doesn’t give me a new url to use, do you know why this is?
Hi Lucas. Sorry it’s not giving you a new url.
When you change the code in one of these tracked activities it will automatically save your changes just on your computer in a cookie so that if you refresh your page you don’t have to start all over again. If you want a new URL you’ll have to press Ctrl+S. You may have to tick the ‘I’m not a robot’ box if that comes up on screen. This is irritating but it limits people exploiting the fact that anyone can save without having to log in. If you’re still having problems, reply here and I’ll email you.