Skip to content
BENIBIX Learn

Logic Error

Development🧩 Programming ConceptsErrors

Also known as Logical Error, Semantic Error

Code that runs with no error message but gives the wrong answer.

Think of it like

Think of it like a map with the right roads but the wrong town at the end. You drive fine and still arrive in the wrong place.

Example

Emma writes a + b / 2 to average 4 and 6. It prints 7.0, because Python divides first. She needed (a + b) / 2.

Why it matters

Logic errors give wrong results that look right. Tests that check the answer, not just that it ran, catch them.

Definition

A logic error is a mistake in the thinking behind the code. The program runs to the end with no message at all. It simply gives the wrong answer. Putting steps in the wrong order or using > where you meant >= are common causes. These are the hardest errors to find, because nothing tells you they are there.

Example code

python
>>> a, b = 4, 6
>>> a + b / 2       # meant to be the average
7.0
>>> (a + b) / 2
5.0
No error appears. The first answer is just wrong.

Common mistake

Thinking no error message means the code works. Check the answer against one you worked out by hand.

Key takeaways

  1. 1
    No message. The program runs to the end.
  2. 2
    Wrong answer. The result looks fine but is not.
  3. 3
    Check results. Compare with an answer you know.

Compare

Learn it properly