When beginners hit an error, most do one of two things: retype the line hoping it goes away, or paste the whole file somewhere and ask what is wrong.
There is a third option that is faster than both, and it is simply reading the error. Python has already done the diagnosis for you.
Read a traceback from the bottom up
Traceback (most recent call last):
File "main.py", line 4, in <module>
total = price + tax
TypeError: unsupported operand type(s) for +: 'int' and 'str'
Three pieces of information, and the most useful is last:
- Bottom line — what went wrong: you tried to add a number to a string
- Middle — which line: line 4,
total = price + tax - Top — how you got there (matters once you have functions)
Beginners read tracebacks top-down and give up at the word "Traceback". Read the last line first, every time.
The five errors you will actually meet
SyntaxError
if age > 18
print("Adult")
SyntaxError: expected ':' — Python could not even parse the code. Ninety percent of the time it is a missing :, an unclosed bracket, or an unclosed quote.
Check the line above the one reported too. An unclosed ( on line 9 is often reported on line 10.
IndentationError
if age > 18:
print("Adult")
IndentationError: expected an indented block. Anything belonging inside if, for, while or def must be indented — four spaces is the convention. Do not mix tabs and spaces; pick one.
NameError
print(usrname)
NameError: name 'usrname' is not defined. You used something that does not exist. Almost always a typo, or a variable used before it was created.
TypeError
age = input("Age: ")
print(age + 1)
TypeError: can only concatenate str (not "int") to str. Wrong kind of value. Here, input() returns text, so wrap it: int(input("Age: ")).
IndexError / KeyError
fruits = ["apple", "banana"]
print(fruits[2])
IndexError: list index out of range. Counting starts at 0, so two items live at 0 and 1. KeyError is the dictionary version — the key is not there. Use .get() when a key may be missing.
When the error message is not enough
Print things. Seriously.
print("DEBUG price =", price, type(price))
Printing the value and its type solves an enormous share of beginner bugs, because most of them are "this is text and I thought it was a number".
Then narrow it down. Comment out half your code. If the error disappears, it was in that half. Repeat. Five rounds of this finds a bug in a 100-line file — far faster than staring.
Change one thing at a time
The most common way beginners turn a small bug into a big one is changing four things at once and re-running. Now something new is broken and you cannot tell which change did it.
One change. Run. Observe. Repeat. It feels slower and is dramatically faster.
The mindset shift
An error is not failure — it is the most precise feedback in the whole craft. It names the problem, points at the line, and often suggests the fix. Compare that to a program that runs fine and quietly produces the wrong number.
A silent wrong answer is a bad day. An error message is a free diagnosis.
Every lesson on Beginner Codes runs your real code and shows you the real error, because learning to read them is not separate from learning to program — it is learning to program.