Usually in the try it section you get code that just works but this tutorial is all about debugging errors, so the code below has 4 common mistakes, each with instructions on how you can fix them.
Ctrl + Enter to run the code.
Click on your score in the top right corner of the code editor to see what your code needs to do.
Any line of code that starts with a # is a comment: it doesn’t affect how the program runs, it’s just there to help explain what the code does.
- Change line 3 to add the missing ”
Remember that you have to balance brackets and quotes. This means that the number of times you start a new quote / set of brackets should be the same as the number of times you end them.
- Check capital letters on line 5
Remember that python throws an error at you if it finds capital letters where it’s not expecting them or if you spell something wrong.
- Add the missing brackets on line 7
Remember that every
(should be balanced with a
- Fix the indentation on line 9
You can indent code (move it to the right) by pressing
Taband you can unindent it (move it to the left) by pressing
Shift + Tab
You can select more than one line at a time and use these shortcuts too which can save loads of time.
On the next page you’ll get some code examples that have been deliberately broken for you to try to fix.
KPRIDE stands for Keywords, Predict, Run, Investigate, Debug and Extend and it’s a way of helping you explore and understand python code. Click on the image below for a set of KPRIDE activities for this python skill.