[Edu-sig] problem with IF

ken ken at joeys.org
Sat Jul 24 00:23:20 CEST 2004


Thanks to all who responded to my problem.
I had tried to use a text string for the right side of the comparison 
and originally a between values, using AND set of decisions.  Also the 
original set of IFs was using elif but all had failed.
The thing tht finally worked was making sure that the numeric for wind 
dirn was as an int.  I thought I had used it as an int() previously and 
didn't look back at that 8-(
Anyway, a simple
dirn = int(dirn)
has fixed the problem 8-)

ken W

Rick Holbert wrote:

>Ken,
>
>I think you should check to see if the bearing is between two values as 
>follows:
>
>#!/usr/bin/env python
>
>def dirnPoint(dirn):
>    if dirn >= 345 and dirn < 22:
>        return "N"
>    elif dirn >= 22 and dirn < 77:
>        return "NE"
>    elif dirn >= 77 and dirn < 112:
>        return "E"
>    elif dirn >= 112 and dirn < 157:
>        return "SE"
>    elif dirn >= 157 and dirn < 202:
>        return "S"
>    elif dirn >= 202 and dirn < 247:
>        return "SW"
>    elif dirn >= 247 and dirn < 292:
>        return "W"
>    elif dirn >= 292 and dirn < 345:
>        return "NW"
>
>inp = int(raw_input("Enter Bearing in degrees: "))
>
>dir = dirnPoint(inp)
>
>print "%d degrees is %s" % (inp, dir)
>
>On Thursday 22 July 2004 21:49, ken wrote:
>  
>
>>hello all,
>>I have been trying to write a program to display the reading from a
>>weather station.  I was trying to change the direction of the wind from
>>degrees to points of compass.  Have tried various if.. elif.. but it
>>seems to take the last option in the list regardless of the value of the
>>degrees.
>>    
>>
>_______________________________________________
>Edu-sig mailing list
>Edu-sig at python.org
>http://mail.python.org/mailman/listinfo/edu-sig
>--
>Scanned by The Sheriff - http://www.isheriff.com/
>
>
>  
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/edu-sig/attachments/20040724/e27f28b4/attachment.htm


More information about the Edu-sig mailing list