A
A
Arti-Jack2016-10-21 15:34:23
Python
Arti-Jack, 2016-10-21 15:34:23

How to avoid inaccuracies when counting different expressions in Python?

The essence of the problem is that there are many unpleasant and subtle points when counting different floating point numbers.
Well, for example, there is a rather trivial probability problem:

 The store has two payment terminals. Each of them can be faulty 
with a probability of 0.3, regardless of the other terminal. Find the probability that 
at least one payment terminal is working. 

The correct answer here is 0.91 , i.e. P = (0.3 * 0.7) + (0.7 * 0.3) + (0.7 * 0.7)
But the python interpreter gives a not very correct result ( 0.9099999999999999).
I know that this is due to the specific implementation of storing real numbers in memory.
But my question is, how exactly can one get around such problems when working with such numbers in Python?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey, 2016-10-21
@Arti-Jack

Read about decimal and fractions

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question