lundi 7 juin 2021

How do I correctly write this if statement?

Suppose that I get the values for valid, d ,sn from a function that I introduced in my program. Then I pass it through the following if statement in python to output the result.

I want the program to print the following statements:

  1. print on if the sn >= 0 and 1<d <90.
  2. print off-right if the sn<0.
  3. print off-left if the d>=90
  4. other than that, for anything that is not valid outputs unknown.

Here is what I wrote, how do I include d when checking the statement?

if valid:
    if sn >= 0 and 1<d <90:
        print(" on ")
        
    else:
        print("off")
else:
    print("unknown")

Aucun commentaire:

Enregistrer un commentaire