I would like to test a set of 3 variables w1,w2,w3
. When the sum of these is equal to 1, I want to print "YATTA"
.
import numpy as np
for w1 in np.arange(0.10,0.45,0.05):
for w2 in np.arange(0.10,0.45,0.05):
for w3 in np.arange(0.10,0.45,0.05):
sumw=w1+w2+w3
if(sumw==1.0):
print "YATTA"
else:
print w1,w2,w3,sumw
When I run this I observe something very weird! For example when my variables are :
w1 = 0.2
w2 = 0.4
w3 = 0.4
sumw
is 1.0 BUT it's not printing "YATTA"
and instead the else
statement is executed.
Why does my code behave like this, and how would I solve this issue?