Solved [1, 2] mean is 1.5 — my test failed LULucasVDOP 20 Sep, 17:43 assert mean([1, 2]) == 1 was my guess. Why does the challenge include this?
JAJackStack20 Sep, 20:49 Solutionreplies: 2To 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.
Comments 4
Join the discussion CommentAlready have an account? Log in
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.I was testing my assumption instead of the correct answer 😅
For 1.5 it's exact, but yeah, isclose is the safe habit.
For floats in general, prefer
math.isclose()over==in tests.