Alterna · учебный материал
Tracking and searching for mistakes
41.1: Trace and search for errors: Short theory, one example, and Python step-by-step.
Что в этом материале
- How it works.
- One example in execution
- Remember
Содержание и основные понятия
The debugging starts with a reproducible entry, an expected result and a first step where the actual state is different.
substance and practice
Grade 11
OGE No. 6/16
EEG No. 16/17/23 - 27
01
How it works.
Debugging isn't random string reshuffling. First, they reproduce the entrance, then they find the first state that breaks the program's contract.
Syntax.
The code is not clear: the symbol is missing, the derogation is broken or the language structure is broken.
Implementation.
The code starts but gets an exception: ZeroDivisionError, IndexError, KeyErrors and others.
Logic.
The program is over, but the result is against the condition.
It's complicated.
The decision is at a small entrance, but there is no time or memory limit.
02
One example in execution
Start the short program and go over the lines. The visualiser only shows the code, current line, variables and output.
The minimum counter-example is the simplest entrance where an error is repeated. It reduces the path and makes the cause visible.
assert
Checks the assumption directly in the code: a false condition arises
AssertionError
Prior to delivery, the debugging point and the essert are usually removed if the output format is to be stringent.
Algorithm map
Read from left to right, then run the code.
1
Start
2
Lock Entry
3
Do One Line
4
Compare with expected status
5
Find the first malfunction
03
Remember
Check the empty entrance, boundaries, repeats, and all negative values.
First fix the expected result, then change the code.
Share the wrong answer and the slow solution: these are different kinds of defects.
Syntax of this page
assert condition, message
Stops the program with AssertionError if it's false.
len(values)
Allows you to check the data size.
enumerate
It helps print the index and state in the diagnostic path.
print
Time shows condition; do not leave an unnecessary conclusion in a strict format.
try / except
Overtakes the expected exception but should not conceal the mistake of the contract.
max
A built-in maximum; for manual debugging, it is useful to compare it to its own algorithm.
return
Returns the result for separate function testing.