This week's assignment was all about debugging. Errors in programming are inevitable so it's important to learn how to begin to approach them while learning how to code. We were provided with three different scripts and had to fix them so that they would all run correctly.
For this class most of our coding is done in Spyder. When you run a script in Spyder, like all IDEs if it gets hung up on an error it will tell you with some kind of error message, like a traceback or syntax error. Sometimes the easiest way to find a problem in your code is simply to run it and then see where the problem is.
Once mistakes such as misspellings or incorrect capitalization are cleared up then the program can run correctly. |
This script had eight bugs that needed to be teased out before it would properly run. |
As you can see in Part A an error message is printed out from the "except" clause. However, Part B runs without issue. |
A Flowchart showing the try/except process
Bug fixing can be tedious but it's important to have different approaches to problem solving. The more errors you fix, the easier it become to figure out other bugs in the future.