03: Python: Syntax errors

Try it:

Find and fix common errors in your code
Syntax errors: Find and fix common errors in your code

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.

Press 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.

Challenges:

  1. 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.

  2. 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.

  3. Add the missing brackets on line 7

    Remember that every ( should be balanced with a )

  4. Fix the indentation on line 9

    You can indent code (move it to the right) by pressing Tab and 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.

Leave a Reply