+ 1
in python 3, i don't understand this question please explain me question in description?
a = 0 and 1 or 0 b = 0 and 0 or 1 c = 1 or 0 and 0 d = 0 or 1 and 0 print(a, b, c, d) why output is this: 0 1 1 0
2 Réponses
+ 1
This is just basic logical operation solving, I am not sure, which part you did not understand.
First you need to know 2 things:
and has higher operation precedence than or.
You propably know, that any zero values represent False (0=False), and any nonzero values represent True (1=True).
Then those should be easy to solve
a = 0 and 1 or 0
First we want to know what is 0 and 1, that's 0.
a = 0 or 0
Then we want to know what is 0 or 0, that's 0.
a = 0
b = 0 and 0 or 1
b = 0 or 1
b = 1
c = 1 or 0 and 0
c = 1 or 0
c = 1
d = 0 or 1 and 0
d = 0 or 0
d = 0
Like you propably noticed, and was always solved before or.
0
a = 0 and 1 or 0
b = 0 and 0 or 1
c = 1 or 0 and 0
d = 0 or 1 and 0
print(a, b, c, d)
why output is this:
0 1 1 0