[Edu-sig] problem with IF

ken ken at joeys.org
Fri Jul 23 03:49:05 CEST 2004


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.
        # let's put in points of compass, instead of degrees
        dirnPoint = "N"
        print dirn
        if dirn >= 22:
                    dirnPoint = "NE"
                print dirnPoint
                if dirn >77 :
                    dirnPoint = "E"
                print dirnPoint
                if dirn >112 :
                    dirnPoint = "SE"
                print dirnPoint
                if dirn > 157 :
                    dirnPoint = "S"
                print dirnPoint
                if dirn > 202 :
                    dirnPoint = "SW"
                print dirnPoint
                if dirn > 247:
                    dirnPoint = "W"
                print dirnPoint
                if dirn > 292:
                    dirnPoint = "NW"
                print dirnPoint
                if dirn > 345:
                    dirnPoint = "N"
                print dirnPoint
                print dirn
  I added the prints to follow the progress through the chioces.  Below 
is the printout from a sample direction;301
NE
E
SE
S
SW
W
NW
N
301
To my way of thinking, it should have stopped at "W" but it seems to be 
getting TRUE for > 292 and > 345.
Any ideas, please.
Thanks..

ken Wallwork
Computing Studies
Co-ordinator
St Joseph's College
Hunters Hill NSW Australia
ken at joeys.org
ken at wyverntech.com



More information about the Edu-sig mailing list