design, write and debug programs that accomplish specific goals, including controlling or simulating physical systems; solve problems by decomposing them into smaller parts.
LO: To debug simple programs.
When we were debugging before we saw that there were two types of errors: commands in the wrong order (or simply the wrong command) and syntax errors (spelling and typing errors). With the introduction of writing functions, typing errors have become much more complex - we have to worry about the indent!
Let's just recap, Python uses indentation to structure programs into organised blocks - it is not just to make it more readable:
def turn_right(): turn_left() #this line is indented because it is part of turn_right() turn_left() #this line is indented because it is part of turn_right() turn_left() #this line is indented because it is part of turn_right() turn_right() #this line is not indented because it is not part of turn_right(), it is calling it
As Reeborg and IDLE (as you'll see later) automatically indents the code after a : most errors will occur when trying to edit the code if it is incorrect.
Take care with the debug code available below (or if you have created your own); to recreate the indentation it is best to go back to the end of the previous line and then press return/enter to ensure the indentation is correct.
Once again, it is important to debug code by trying to run it and respond to the errors or mistakes Reeborg makes rather than just to see it as an exercise in proofreading.