🧩Logic Error
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
Example code
python
>>> a, b = 4, 6
>>> a + b / 2 # meant to be the average
7.0
>>> (a + b) / 2
5.0Common mistake
Key takeaways
- 1No message. The program runs to the end.
- 2Wrong answer. The result looks fine but is not.
- 3Check results. Compare with an answer you know.