Truth and Floating Point Woes in Python

A Python Brain Teaser

Miki Tebeka
The Pragmatic Programmers
3 min readJul 2, 2021

--

You wrote a very simple function, like this:

And you’d like to test your function, like this:

When you run pytest, you see a strange error:

Your curiosity is sparked, so you start digging in. You fire up ipython and take a look:

So far, so good. Let’s compare to expected:

--

--