I dont get this!

Richard Jones richard at bizarsoftware.com.au
Thu Aug 23 19:07:34 EDT 2001


On Friday 24 August 2001 08:16, Peter Sundling wrote:
> Help! :)
> I have been programming in python for some time now, and today i
> found a strange bug in my code i cant get rid of...
>
> Here is a code snippet where something is wrong somewhere:
>
>
> def check_hilo(i):
> 	if value[i] < low[i]:
> 		return 1
>
> 	if value[i] > high[i]:
> 		return 2
>
> 	return 0
>
>
> ...Simple, huh? I have never had any trouble with something like this
> before.
> The thing is that this procedure always returns 1.
> I have tried to rewrite this little source code a couple of times,
> in many different ways, and it still returns 1!
>
> If i compare value to high before i compare it to low, it still returns
> 1.
>
> As an example: value[i] was 103, low[i] was 25 and high[i] was 35.
> As far as i know, 103 is greater than 25. But python seemes to disagree
> on that...
> ( if i start the python alone and writes
> print 103 < 25
> it responds 0, But what the hell is wrong now??)

I suspect your values of "value", "high" and "low" may not be what you think 
they are. The function works fine for me...


>>> def check_hilo(i):
...          if value[i] < low[i]:
...                  return 1
...          if value[i] > high[i]:
...                  return 2
...          return 0
... 
>>> value = [103]
>>> low = [25]
>>> high = [35]
>>> check_hilo(0)
2


    Richard




More information about the Python-list mailing list