[Edu-sig] problem with IF

Rick Holbert holbert.13 at osu.edu
Sat Jul 24 14:10:59 CEST 2004


Thanks for the input John.

Another idea for north is to test if it is >= 345 or < 22.

Also, I've recommended your book to the CIS department here at OSU.

Sincerely,

Rick

On Friday 23 July 2004 20:42, John Zelle wrote:
> Maybe this isn't really the forum, but I can't resist a couple quick
> comments on this example.
>
> Since this is a multiway decision (that is, 8 mutually exclusive
> outcomes based on a single decision value), elif is definitely
> appropriate but having two conditions on each clause is redundant and
> often leads to errors. In fact there is an error in the code below,
> since it can nver return 'N' (dirn can't be both >= 345 and < 22). Of
> course, North is a bit of a special case; one way to do that is to split
> "N" into its two cases:
>
> if dirn < 22: return "N"
> elif dirn < 77: return "NE"
> elif dirn < 112: return "E"
> elif dirn < 157: return "SE"
> etc...
> elif dirn < 345: return "NW"
> else: return "N" # anything >= 345
>


More information about the Edu-sig mailing list