Reputation: 353
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:
on
if the sn >= 0
and 1<d <90
.off-right
if the sn<0
.off-left
if the d>=90
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")
Upvotes: 0
Views: 83
Reputation: 2719
if valid:
if sn >= 0 and d > 1 and d < 90:
print(" on ")
elif sn < 0:
print("off-right")
elif d >= 90:
print("off-left")
else:
print("unknown")
Upvotes: 4
Reputation: 418
Not sure what you want. But most probably you want to do this i guess?
if valid:
if sn >= 0 and (d>1 and d<90):
print(" on ")
else:
if sn<0:
print("off-right")
elif d>=90:
print('off-left')
else:
print("unknown")
This is a self explanatory answer.. If you get confused by 1<d<90 then you can use what i did above
Upvotes: 3