What will be the value of x from the following code snippet?
A, B = 10,3
X = A if (A/B==3) else B
print(X)
(B) 10
(C). True
(D) False
(A) 3
Answers
Answered by
3
Answer:
(A) 3
Explanation:
In line 1,
value 10 is stored in A, and value 3 is stored in B.
In line 2,
it says, if A/B==3, value of A is stored in X, else, value of B is stored in X.
The main thing to notice over here is,
A/B is a normal division which give the value in decimals.
So, A/B=10/3 gives 3.33333... which is not equal to 3.
As A/B is not equal to 3,
The value of B is stored in X; i.e., X=3
Note: X would have been stored with the value of A, if we use floor division (A//B), which rounds up the value of decimal too the nearest lowest integer.
Attachments:
Similar questions