0
Probabilities = \
    [0.27,
     0.33,
     0.35,
     0.03,
     0.01,
     0.007,
     0.002,
     0.0007,
     0.0002,
     0.0001]
result = 0
for probability in Probabilities:
    result += probability
print(result)

The output is:

1.0000000000000002

Why?

I also tried the sum() function but the result is the same.

Yam Mesicka
  • 6,243
  • 7
  • 45
  • 64
Ayktron
  • 9
  • 1
  • 1
    This is due to floating point errors - look at [this answer](https://stackoverflow.com/questions/19473770/how-to-avoid-floating-point-errors) – rassar Jan 29 '20 at 14:27
  • This is explained in [the official Python tutorial](https://docs.python.org/3/tutorial/floatingpoint.html#representation-error). – Jongware Jan 29 '20 at 15:37

0 Answers0