Skip to main content
Python Bug Hunt Medium +20 XP

Integer Division Bug

This should return a float average but returns an integer.

PythonFind the bug
1def average(numbers):
2 total = sum(numbers)
3 return total // len(numbers)
The bug is on line 3

Select the correct fix

Show answer and explanation

Answer: Use / instead of //

// is floor division (rounds down to integer). Use / for true division that returns a float.

Hint: // and / behave differently.

What this challenge tests

Bug Hunt in Python: operators, division.

Related challenges