[Edu-sig] problem with IF
Rick Holbert
holbert.13 at osu.edu
Fri Jul 23 22:53:33 CEST 2004
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.
More information about the Edu-sig
mailing list