Computer Science
Evaluate and Justify:
(i) false and None
(ii) 0 and None
(iii) True and None
(iv) None and None
Answer
(i) This produces an error as false is an invalid literal in Python. It should be False. Had the expression being False and None, the return value will be False.
(ii) This logical expression evaluates to 0. As first operand of and operator is false so it will return the first operand itself.
(iii) This logical expression evaluates to None. As first operand of and operator is True so it will return the second operand.
(iv) This logical expression evaluates to None. As first operand of and operator is false so it will return the first operand itself.
Related Questions
Evaluate the following for each expression that is successfully evaluated, determine its value and type for unsuccessful expression, state the reason.
(a) len("hello") == 25/5 or 20/10
(b) 3 < 5 or 50/(5 - (3 + 2))
(c) 50/(5 - (3 + 2)) or 3 < 5
(d) 2 * (2 * (len("01")))
Evaluate and Justify:
(i) 22 / 17 = 37 / 47 + 88 /83
(ii) len('375')**2
Evaluate and Justify:
(i) 22.0/7.0 - 22/7
(ii) 22.0/7.0 - int(22.0/7.0)
(iii) 22/7 - int (22.0)/7
Evaluate and Justify:
(a) 0 or None and "or"
(b) 1 or None and 'a' or 'b'
(c) False and 23
(d) 23 and False
(e) not (1 == 1 and 0 != 1)
(f) "abc" == "Abc" and not (2 == 3 or 3 == 4)
(g) False and 1 == 1 or not True or 1 == 1 and False or 0 == 0