Test Series - python

Test Number 10/108

Q: What will be the output of the following Python code snippet?

bool(‘False’)
bool()
A. True True
B. False True
C. False False
D.  True False
Solution: The Boolean function returns true if the argument passed to the bool function does not amount to zero. In the first example, the string ‘False’ is passed to the function bool. This does not amount to zero and hence the output is true. In the second function, an empty list is passed to the function bool. Hence the output is false.
Q: What will be the output of the following Python code snippet?

not(3>4)
not(1&1)
A. True True
B. True False
C. False True
D.  False False
Solution:  The function not returns true if the argument amounts to false, and false if the argument amounts to true. Hence the first function returns false, and the second function returns false.
Q: What will be the output of the following Python code if the system date is 21st June, 2017 (Wednesday)?

[] or {}
{} or []
A.  [] {}
B.  [] []
C.  {} []
D. {} {}
Solution: The code shown above shows two functions. In both the cases the right operand is returned. This is because each function is evaluated from left to right. Since the left operand is false, it is assumed that the right operand must be true and hence the right operand is returned in each of the above case.
Q: What will be the output of the following Python code?

class Truth:
	pass
x=Truth()
bool(x)
A. pass
B. true
C. false
D. error
Solution: If the truth method is not defined, the object is considered true. Hence the output of the code shown above is true.
Q: What will be the output of the following Python code?

if (9 < 0) and (0 < -9):
    print("hello")
elif (9 > 0) or False:
    print("good")
else:
    print("bad")
A. error
B. hello
C. good
D. bad
Solution: The code shown above prints the appropriate option depending on the conditions given. The condition which matches is (9>0), and hence the output is: good.
Q: Which of the following Boolean expressions is not logically equivalent to the other three?
A. not(-6<0 or-6>10)
B. -6>=0 and -6<=10
C. not(-6<10 or-6==10)
D. not(-6>10 or-6==10)
Solution: The expression not(-6<0 or -6>10) returns the output False.
The expression -6>=0 and -6<=10 returns the output False.
The expression not(-6<10 or -6==10) returns the output False.
The expression not(-6>10 or -6==10) returns the output True.
Q: What will be the output of the following Python code snippet?

not(10<20) and not(10>30)
A. True
B. False
C. Error
D. No output
Solution: The expression not(10<20) returns false. The expression not(10>30) returns true. The and operation between false and true returns false. Hence the output is false.

You Have Score    /7