# Logic Error

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

**Field:** Software Development  
**Category:** Programming Concepts  
**Also known as:** Logical Error, Semantic Error

## 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.

## 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

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

## 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.

## Why it matters

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

## Common mistake

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

## Three principles

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

## Related terms

- [Error](https://learn.benibix.com/term/development/error)
- [Bug](https://learn.benibix.com/term/development/bug)
- [Runtime Error](https://learn.benibix.com/term/development/runtime-error)
- [Debugging](https://learn.benibix.com/term/development/debugging)
- [Off-by-One Error](https://learn.benibix.com/term/development/off-by-one-error)

## Told apart from

- [Runtime Error vs Logic Error](https://learn.benibix.com/compare/runtime-error-vs-logic-error): People think a program that runs to the end with no message is working, and it may not be. A runtime error stops the program while it runs and names the line, such as a divide by zero. A logic error stops nothing. The program finishes and the answer is just wrong. Only a check of the result will catch it.

## Taught in

- [Bugs and Error Types](https://learn.benibix.com/learn/development-concepts/bugs-and-error-types): Programming Basics, 15/18

---

Source: https://learn.benibix.com/term/development/logic-error
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-19
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
