Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Python Basics Types and Branching Numeric

I tried something different

instead of 0.1+0.1+0.1-0.3 i wrote 0.2+0.2+0.2-0.6 and i got 1.1102230246251565e-16 is it the same as 5.5.....?

2 Answers

Steven Parker
Steven Parker
216,016 Points

It's different, but it's also an example of how small errors will appear in floating-point calculations.

Hambone F
Hambone F
3,569 Points

Interestingly - it's actually exactly twice the 5.5 number seen in the video. It kind of makes sense, double the magnitude of the inputs, double the magnitude of the error.

You can try it right in the REPL:

>>> err1 = 0.1 + 0.1 + 0.1 - 0.3
>>> err1
>>> err2 = 0.2 + 0.2 + 0.2 - 0.6
>>> err2
>>> err1 * 2 == err2