I’m trying to combine multiple not conditions in a single line but I can’t make it. This is how the conditional statements should be built upon:
when stat
has a value and both the value of alternative
and successor
are nothing then only the script should print true
.
When I try the following, I get true
as the result.
JavaScript
x
7
1
stat = "o"
2
alternative = ""
3
successor = ""
4
5
if stat and not (alternative and successor):
6
print("true")
7
However, When I execute the following, I also get true
as the result
JavaScript
1
7
1
stat = "o"
2
alternative = "p"
3
successor = ""
4
5
if stat and not (alternative and successor):
6
print("true")
7
How can I rectify the condition above to serve the purpose?
Advertisement
Answer
both the value of
alternative
andsuccessor
are nothing
This literally translates to
JavaScript
1
2
1
not alternative and not successor
2
By De Morgan’s laws it is equivalent to
JavaScript
1
2
1
not (alternative or successor)
2