Begginer: problems with IF and ELIF

Lyle Johnson jlj at cfdrc.com
Tue May 28 11:27:02 EDT 2002


> When I input an altitude of 1 and a distance of 20, which is obviously
> outside of my area the program reacts correctly.  However if i enter an
> altitude of 600 and a distance of six, which should also be outside my
area
> it doesn't respond.  Can anyone go over my code to see what i have done
> wrong?

You're using the binary bit-wise logical operators "&" and "|" instead of
the regular logical operators "and" and "or". So that first block of code
(labelled Case 1) should instead look like this:

    if altitude <= 1199 and altitude >= 0:
        if distance >= 6:
            print ("Traffic outside of class C airspace")

        elif distance <= 5 or distance >= 0:
            print ("You are inside class C airspace")

        else:
            print ("ERROR!! distance negative")

You'll want to make a similar change for the other blocks in the program.

Hope this helps,

Lyle






More information about the Python-list mailing list