What is a bug in programming?
In short
A bug is a mistake in a program that makes it crash or do something it shouldn't. Finding and fixing bugs is called debugging.
Some bugs stop a program straight away with an error message. Those are the friendly ones, because the message usually says which line went wrong and why. Others let the program run but give the wrong answer, and you only find them by checking the results.
Every programmer writes bugs, every day. The skill is reading the error, working out what the code really does step by step and testing your fix.
Python
This should print the average of three scores, but it's wrong
scores = [8, 6, 10]
average = scores[0] + scores[1] + scores[2] / 3
print(average)Output
17.333333333333332Python
Fixed: add them up first, then divide
scores = [8, 6, 10]
average = (scores[0] + scores[1] + scores[2]) / 3
print(average)Output
8.0Learn it properly
These free lessons teach it step by step, with questions and a program you write yourself.
- Reading TracebacksLearn Python →
- Tracing and Debugging LoopsLearn Python →
- Reading Error MessagesLearn JavaScript →
Try your first lesson free
Codiqo teaches coding in five-minute lessons with real code. Free on the web, iPhone and Android.