I wrote the following code:
for value in values:
p = round(stats[value] / stats.sum(),2)
e = round(-p * math.log(p,2),2)
print (e)
plist.append((value,p,e))
the "print(e)" displays the values 0.46 and 0.53. That's what's expected. When I print the list, I obtain the following:
[('Y', 0.57999999999999996, 0.46000000000000002),
('N', 0.41999999999999998, 0.53000000000000003)]
the value of 'e' that was rounded properly, is now appended to the list as 0.46000000000000002 and 0.53000000000000003.
Why is that and how can I get the rounded values on 2 decimals in my tuple ?