Q. Create two more variables r and s as r = 0 and s = 0.0 and practice the following expressions.


x = 29.0
y = 13
z = 2
p = 0.5
q = 12.79

 
S. No. Expression Result Reason
1 r and p
2 p and r
3 p and q
4 q and p
5 r or p
6 p or r
7 p or z
8 z or p
9 p or q
10 q or p
11 not q or p
12 a and not q
13 s and x
14 not s and x
15 z or s
16 s or z
17 z - 2 or s
18 s or z - 2
19 z + 2 or s
20 s or z + 2

Answer :-

Note :- In python ‘0’ and ‘’ (empty string) treated as False and all other number (e.g. 1, 1.3652, -9.25, 6, 0.0001 ) and “ABC…” treated as True.

 
S. No. Expression Result Reason
1 r and p 0 In and operator if one of them is zero then it will return zero.
2 p and r 0 In and operator if one of them is zero then it will return zero.
3 p and q 12.79 If both value is non zero the and operator return last value.
4 q and p 0.5 If both value is non zero the and operator return last value.
5 r or p 0.5 In or operator if it is True then it returns non zero value.
6 p or r 0.5 In or operator if it is True then it returns non zero value.
7 p or z 0.5 In or operator if both value is true then it will return first value.
8 z or p 2 In or operator if both value is true then it will return first value.
9 p or q 0.5 In or operator if both value is true then it will return first value.
10 q or p 12.79 In or operator if both value is true then it will return first value.
11 not q or p 0.5 Here first True is converted into False due to not operator so or operator return second True
12 a and not q '' Here empty operator treated as false
13 s and x 0.0 Here 0.0 treated as False
14 not s and x 29.0 In and operator if both value is true then it will return second value.
15 z or s 2 In or operator if both value is true then it will return first value.
16 s or z 2 In or operator if both value is true then it will return True value from both of them.
17 z - 2 or s 0.0 In or operator if both value is False then it will return second value.
18 s or z - 2 0 In or operator if both value is False then it will return second value.
19 z + 2 or s 4 In or operator if both value is true then it will return first value.
20 s or z + 2 4 In or operator it will return True value from both of them.

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post