I was working with a list of probabilities for an assignment, so naturally I wanted to add something to my program to make sure the list equaled '1'.
I was working with an example list [0.1, 0.2, 0.7]. Here's a small snippet of my code
list = [0.7, 0.2, 0.1]
total = 0
for i in list:
total += i
if total != 1.0:
print 'Bad'
else:
print 'Good'
print total
The problem seems to stem from the order of the list? If I put in the list in the code, it tells me it doesn't equal one. However, if I switch around the values [0.1, 0.2, 0.7], suddenly it equals 1.
Can anyone explain what's going on? I'd really like it to tell me it equals '1' regardless of the order of the list.