About the challenge Edge cases All discussions about it
Solved

[1, 2] mean is 1.5 — my test failed

LucasVDOP

assert mean([1, 2]) == 1 was my guess. Why does the challenge include this?

10

Comments 4

Join the discussion

Already have an account? Log in

  1. JackStack Solutionreplies: 2

    To catch implementations that use // instead of / and silently drop the fraction. Your assert should expect 1.5. Choosing test inputs that would expose likely mistakes is the real skill here.

    10
    1. LucasVDOPreplies: 1

      I was testing my assumption instead of the correct answer 😅

      0
    2. TomBecker

      For floats in general, prefer math.isclose() over == in tests.

      6