[Edu-sig] problem with IF
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-)
Rick Holbert wrote:
>I think you should check to see if the bearing is between two values as
> 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:
>>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
>Edu-sig mailing list
>Edu-sig at python.org
>Scanned by The Sheriff - http://www.isheriff.com/
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Edu-sig