# [Tutor] when 1 is not equal to 1...??

Carla A. Ng c-ng at northwestern.edu
Fri Jul 16 22:43:51 CEST 2004

```I've put in an error catch in a program to alert me when the equations
I'm trying to solve have an error.

Basically, if the sum of contributions to something does not equal 1, it
should print out an error message (I don't plan on keeping this in my
code, since it's bulky and outputs a bunch of stuff to the screen, but I
wanted to make sure everything was working correctly).  But I'm getting
an error message when it *does* equal 1.

Here's the code:

diet=resize(base, (max,1))
for i in range(max):
for j in range(max):
diet[i,0]+=web[i,j]
for i in range(max):
if diet[i,0]<1.0 and i+1 not in Basal:
print "wij for ", i+1, "has an error!"

print diet

Just to double-check that my check was working, I printed "diet" at the
end.  Then when I run it, I get:

wij for  1 has an error!
wij for  2 has an error!
wij for  3 has an error!
wij for  4 has an error!
wij for  5 has an error!
wij for  6 has an error!
wij for  7 has an error!
wij for  12 has an error!
wij for  13 has an error!
wij for  14 has an error!
wij for  15 has an error!
wij for  21 has an error!
wij for  22 has an error!
wij for  27 has an error!
wij for  28 has an error!
wij for  43 has an error!
wij for  54 has an error!
wij for  57 has an error!
wij for  58 has an error!
wij for  61 has an error!
wij for  63 has an error!
wij for  79 has an error!
wij for  83 has an error!
[[ 1.]
[ 1.]
[ 1.]
[ 1.]
[ 1.]
[ 1.]
[ 1.]
[ 1.]
[ 1.]
[ 1.]
[ 0.]
[ 1.]
[ 1.]
[ 1.]
[ 1.]
[ 1.]
[ 1.]
[ 1.]
[ 1.]
[ 1.]
[ 1.]
[ 1.]
[ 1.]
[ 1.]
[ 1.]
[ 1.]

(I didn't print out the whole thing, just enough to show it's not working).
Obviously, since diet[0,0]=1, I should not get the error message:

wij for 1 has an error!

Any ideas out there?  I thought it might be a float/integer problem, but
everything is in floats, so I'm stumped.

Thanks!

Carla A. Ng
===================================
Northwestern University
Department of Chemical and Biological Engineering