Explanations "Top Python Quiz Questions"
349 subscribers
80 photos
1 link
Explanations "Top Python Quiz Questions"
Download Telegram
What is the output of the code snippet?

False False True True False
False False True True True
True True True True True
True True True True False
True True 0 0 False
True True 3 1 False
True True 3 1 True
Error
None of the above

Explanation:
True: This keyword is used to represent a boolean true. If a statement is true, “True” is printed.
False: This keyword is used to represent a boolean false. If a statement is false, “False” is printed.
None: This is a special constant used to denote a null value or a void. It’s important to remember, 0, any empty container(e.g empty list) does not compute to None.
It is an object of its datatype – NoneType. It is not possible to create multiple None objects and can assign them to variables.
Additionally, in Python, True == 1 and False == 0, as True and False are type bool, which is a subtype of int. When you use the operator +, it is implicitly adding the integer values of True and False.
That's why True + True + True = 1 + 1 + 1 = 3 and True + False + False = 1 + 0 + 0 = 1.
What will be the output of the code?

0
1
10
20
50
Error
None of the above

Explanation:
The above function basically calculates the greatest common divisor of 2 numbers recursively.
During 1st call of "solve" function a = 20, b = 50, b % a = 10. During 2nd: a = 10, b = 20, b % a = 0.
Finally during the next call a = 0, b = 10 so value of b (equal to 10) is returned.
What will be the output of the code?

{'Hello':'World', 'First': 1}
{'World':'Hello', '1': 'First'}
{'Hello':1, 'First': 'World'}
{'Hello':'First', 'World': 1}
Error
None of the above

Explanation:
This is an example of dictionary comprehension in Python, in which we are reversing the key-value pairs from the 1st dictionary into the 2nd.
What will be the value of 'result' variable?

[1, 3, 5, 7, 8]
[1, 7, 8]
[1, 2, 4, 7, 8]
Error
None of the above

Explanation:
Here, 'result' is a list which is extending three times. When first time 'extend' function is called for 'result', the inner code generates a generator object, which is further used in 'extend' function. This generator object contains the values which are in 'list1' only (not in 'list2' and 'list3').
Same is happening in second and third call of 'extend' function in these generator object contains values only in 'list2' and 'list3' respectively. So, 'result' variable will contain elements which are only in one list (not more than 1 list).
What is the value of L at the end of execution of the program?

[6.222e-04, ‘aboy’, True, 641]
[6.2202, ‘aboy’, 1, 641]
[6.2202, ‘aboy’, False, 87]
TypeError
None of the above

Explanation:
The for loop will run for i = 0 to i = 3, i.e. 4 times(len(L) = 4). 2e-04 is same as 0.0002, thus L[i] = 6.22 + 0.0002 = 6.2202. String addition will result in concatenation, ‘a’ + ‘boy’ = ‘aboy’. False + True is True, it’ll return the integer value of 1. As tuples are immutable, the code will end with TypeError, but elements of L will be updated.
What is the output of the code?

12
11
11.001199999999999
TypeError
None of the above

Explanation:
Integer value of 2e-04(0.0002) is 0, True holds a value 1 and False a 0, integer value of 1.001 is 1. Thus total 0 + 1 + 0 + 8 + 1 + 1 = 11.
What is the output of the code?

False
True
None
Error
None of the mentioned

Explanation:
Each elements of the tuples are compared one by one and if maximum number of elements are there in tuple1 which are greater or equal to corresponding element of tuple2 then tuple1 is said to be greater than tuple2.