Code -
i, j, k = 4, -1, 0
w = i or j or k # w = (4 or -1) or 0 = 4
x = i and j and k # x = (4 and -1) and 0 = 0
y = i or j and k # y = (4 or -1) and 0 = 4
z = i and j or k # z = (4 and -1) or 0 = -1
print(w, x, y, z)
Solution and Explanation -
Here's the explanation for each variable:
w: It takes the first non-zero value from left to right in the sequence (i, j, k). In this case, the first non-zero value is 4.
x: It takes the first zero value from left to right in the sequence (i, j, k). In this case, the first zero value is 0.
y: It takes the first non-zero value from left to right in the sequence (i, j) and then evaluates the result with k using the "and" operator. In this case, (4 or -1) evaluates to 4, and 4 and 0 evaluates to 0.
z: It takes the first non-zero value from left to right in the sequence (i, j) and then evaluates the result with k using the "or" operator. In this case, (4 and -1) evaluates to -1, and -1 or 0 evaluates to -1.
So, the output of the print statement will be: 4 0 4 -1
0 Comments:
Post a Comment