1.2.1.8 Begin your Python journey
How to spoil and fix your code
You may have noticed that the error message generated for the previous error is quite different from the first one.

This is because the nature of the error is different and the error is discovered at a different stage of interpretation.
The editor window will not provide any useful information regarding the error, but the console windows might.
The message (in red) shows (in the subsequent lines):
- the traceback (which is the path that the code traverses through different parts of the program - you can ignore it for now, as it is empty in such a simple code);
- the location of the error (the name of the file containing the error, line number and module name); note: the number may be misleading, as Python usually shows the place where it first notices the effects of the error, not necessarily the error itself;
- the content of the erroneous line; note: IDLE’s editor window doesn’t show line numbers, but it displays the current cursor location at the bottom-right corner; use it to locate the erroneous line in a long source code;
- the name of the error and a short explanation.
Experiment with creating new files and running your code. Try to output a different message to the screen, e.g.,
roar!
, meow
, or even maybe an oink!
. Try to spoil and fix your code - see what happens.
Comments
Post a Comment