1

Something weird. I want to test if a sum of a tuple elements is 1 and then assert if not.

my_tuple=(0.8,0.2,0)
assert((sum(my_tuple)==1))

This works. It works for other tuples like ( 1,0,0) or (0.1,0.2,0.7). But it raises an error for this tuple (0.7,0.2,0.1) eventhough the sum is clearly 1 !!

Do you have any idea about this ? Thank you

Volta
  • 53
  • 9
  • Can you please provide us with an example of how did you make the tests with the other tuples, exactly how you wrote them in the code and etc. – Fanatique Aug 03 '18 at 09:26
  • hmm this is strange. `sum((0.8,0.2,0))==1` is `True` but `sum((0.7,0.2,0.1))==1` is `False`. The latter evaluates to `0.9999999999999999` for some reason. – Ashish Acharya Aug 03 '18 at 09:28
  • Just like I showed in the post. For example to test the tuple (0.7,0.2,0.1) i do this : my_tuple=(0.1,0.2,0.7) and then assert((sum(my_tuple)==1)) – Volta Aug 03 '18 at 09:29

0 Answers0