0% found this document useful (0 votes)
60 views4 pages

2 MCQ Class 11th Operators

The document contains multiple-choice questions (MCQs) focused on Python's operator precedence and associativity, along with Boolean expressions. Each question is followed by answer options, and some include explanations for the correct answers. The document serves as a study guide for understanding Python programming concepts related to expressions and logical operations.

Uploaded by

Palak Soni
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
60 views4 pages

2 MCQ Class 11th Operators

The document contains multiple-choice questions (MCQs) focused on Python's operator precedence and associativity, along with Boolean expressions. Each question is followed by answer options, and some include explanations for the correct answers. The document serves as a study guide for understanding Python programming concepts related to expressions and logical operations.

Uploaded by

Palak Soni
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

MCQ PYTHON ASSOCIATIVITY By Gajendra Sir Mo. No.

: 9810301034
PRECEDENCE AND ASSOCIATIVITY – 1
1. The value of the expressions 4/(3*(2-1)) and 4/3*(2-1) is the same. State whether True or false. a) True b) False
2. The value of the expression: 4+3%5
a) 4 b) 7 c) 2 d) 0
3. Evaluate the expression given below if A= 16 and B = 15. A % B // A
a) 0.0 b) 0 c) 1.0 d) 1
4. Which of the following operators has its associativity from right to left?
a) + b) // c) % d) **
5. What is the value of x if: x = int(43.55+2/2)
a) 43 b) 44 c) 22 d) 23
6. What is the value of the following expression? 2+4.00, 2**4.0
a) (6.0, 16.0) b) (6.00, 16.00) c) (6, 16) d) (6.00, 16.0)
7. Which of the following is the truncation division operator?
a) / b) % c) // d) |
8. What are the values of the following expressions: 2**(3**2), (2**3)**2, 2**3**2
a) 64, 512, 64 b) 64, 64, 64 c) 512, 512, 512 d) 512, 64, 512
9. What is the value of the following expression: 8/4/2, 8/(4/2)
a) (1.0, 4.0) b) (1.0, 1.0) c) (4.0. 1.0) d) (4.0, 4.0)
10. What is the value of the following expression: float(22//3+3/3)
a) 8 b) 8.0 c) 8.3 d) 8.33
PRECEDENCE AND ASSOCIATIVITY – 2
1. What is the output of the following expression: print (4.00/(2.0+2.0))
a) Error b) 1.0 c) 1.00 d) 1
2. Consider the expression given below. The value of X is: X = 2+9*((3*12)-8)/10
a) 30.0 b) 30.8 c) 28.4 d) 27.2
3. Which of the following expressions involves coercion when evaluated in Python?
a) 4.7 – 1.5 b) 7.9 * 6.3 c) 1.7 % 2 d) 3.4 + 4.6
4. What is the value of the following expression: 24//6%3, 24//4//2
a) (1,3) b) (0,3) c) (1,0) d) (3,1)
5. Which among the following list of operators has the highest precedence? +, -, **, %, /, <<, >>, |
a) <<, >> b) ** c) | d) %
6. What is the value of the expression: float(4+int(2.39)%2)
a) 5.0 b) 5 c) 4.0 d) 4
7. Which of the following expressions is an example of type conversion?
a) 4.0 + float(3) b) 5.3 + 6.3 c) 5.0 + 3 d) 3 + 7
8. Which of the following expressions results in an error?
a) float(‘10’) b) int(‘10’) c) float(’10.8’) d) int(’10.8’)
9. What is the value of the expression: 4+2**5//10
a) 3 b) 7 c) 77 d) 0
10. The expression 2**2**3 is evaluates as: (2**2)**3. State whether this statement is True or false. a) True b)
False

BOOLEAN
1. The output of the snippet of code shown below? bool(‘False’), bool()
a) True True b) False True c) False False d) True False

Page 1 of 4 Computer Science 083 PYTHON [email protected]


MCQ PYTHON ASSOCIATIVITY By Gajendra Sir Mo. No. : 9810301034
2. What is the output of the snippet of code shown below? ['hello', 'morning'][bool('')]
a) error b) no output c) hello d) morning
3. What is the output of the code shown below? not(3>4), not(1&1)
a) True True b) True False c) False True d) False False
4. What is the output of the code shown? ['f', 't'][bool('spam')]
a) t b) f c) No output d) Error
5. What is the output of the code shown below?
l=[1, 0, 2, 0, 'hello', '', []]
list(filter(bool, l))
a) Error b) [1, 0, 2, 0, ‘hello’, ”, []] c) [1, 0, 2, ‘hello’, ”, []] d) [1, 2, ‘hello’]
6. What is the output of the code shown below?
if True:
print(bool())
a) 0 b) True c) False d) error
7. What is the output of the code shown below?
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
8. 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)
9. The output of the line of code shown below is: not(10<20) and not(10>30)
a) True b) False c) Error d) No output
10. The output of the line of code shown below is: not(10>20) or not(10<30)
a) True b) False c) Error d) No output

Page 2 of 4 Computer Science 083 PYTHON [email protected]


MCQ PYTHON ASSOCIATIVITY By Gajendra Sir Mo. No. : 9810301034
PRECEDENCE AND ASSOCIATIVITY – 1 REASION
Ans 1. a [ Although the presence of parenthesis does affect the order of precedence, in the case shown above,
it is not making a difference. The result of both of these expressions is 1.333333333. Hence the statement is True.
]
Ans 2. b [ The order of precedence is: %, +. Hence the expression above, on simplification results in 4 + 3 =
7. Hence the result is 7. ]
Ans 3. b [ The above expression is evaluated as: 16%15//16, which is equal to 1//16, which results in 0. . ]
Ans 4. d [ All of the operators shown above have associativity from left to right, except exponentiation operator
(**) which has its associativity from right to left. . ]
Ans 5. b [ The expression shown above is an example of explicit conversion. It is evaluated as int(43.55+1) =
int(44.55) = 44. Hence the result of this expression is 44. ]
Ans 6. a [ The result of the expression shown above is (6.0, 16.0). This is because the result is automatically
rounded off to one decimal place. ]
Ans 7. c [ // is the operator for truncation division. It it called so because it returns only the integer part of the
quotient, truncating the decimal part. For example: 20//3 = 6. ]
Ans 8. d [ Expression 1 is evaluated as: 2**9, which is equal to 512.Expression 2 is evaluated as 8**2, which
is equal to 64. The last expression is evaluated as 2**(3**2). This is because the associativity of ** operator is from
right to left. Hence the result of the third expression is 512. ]
Ans 9. advertisement
Ans 10. a [ The above expressions are evaluated as: 2/2, 8/2, which is equal to (1.0, 4.0). ]
Ans 11. b [ The expression shown above is evaluated as: float( 7+1) = float(8) = 8.0. Hence the result of this
expression is 8.0. ]
PRECEDENCE AND ASSOCIATIVITY – 2 REASION
Ans 1. b [ The result of the expression shown above is 1.0 because print rounds off digits. ]
Ans 2. d [ The expression shown above is evaluated as: 2+9*(36-8)/10, which simplifies to give 2+9*(2.8),
which is equal to 2+25.2 = 27.2. Hence the result of this expression is 27.2. ]
Ans 3. c [ Coercion is the implicit (automatic) conversion of operands to a common type. Coercion is
automatically performed on mixed-type expressions. The expression 1.7 % 2 is evaluated as 1.7 % 2.0 (that is,
automatic conversion of int to float). ]
Ans 4. a [ The expressions are evaluated as: 4%3 and 6//2 respectively. This results in the answer (1,3). This
is because the associativity of both of the expressions shown above is left to right. ]
Ans 5. b [ The highest precedence is that of the exponentiation operator, that is of **.]
Ans 6. c [ The above expression is an example of explicit conversion. It is evaluated as: float(4+int(2.39)%2)
= float(4+2%2) = float(4+0) = 4.0. Hence the result of this expression is 4.0. ]
Ans 7. a [ Type conversion is nothing but explicit conversion of operands to a specific type. Options ‘b’ and
‘c’ are examples of implicit conversion whereas option ‘a’ is an example of explicit conversion or type conversion.
Ans 8. d [ All of the above examples show explicit conversion. However the expression int(’10.8’) results in
an error. ]
Ans 9. b [ The order of precedence is: **, //, +. The expression 4+2**5//10 is evaluated as 4+32//10, which is
equal to 4+3 = 7. Hence the result of the expression shown above is 7. ]
Ans 10. b [ The value of the expression (2**2)**3 = 4**3 = 64. When the expression 2**2**3 is evaluated in
python, we get the result as 256, because this expression is evaluated as 2**(2**3). This is because the associativity
of exponentiation operator (**) is from right to left and not from left to right. ]
BOOLEAN REASION

Page 3 of 4 Computer Science 083 PYTHON [email protected]


MCQ PYTHON ASSOCIATIVITY By Gajendra Sir Mo. No. : 9810301034
Ans 1. d [ 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. ]
Ans 2. c [ The line of code shown above can be simplified to state that ‘hello’ should be printed if the argument passed to the
Boolean function amounts to zero, else ‘morning’ will be printed. ]
Ans 3. b [ 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. ]
Ans 4. a [ The line of code can be translated to state that ‘f’ is printed if the argument passed to the Boolean function amount to
zero. Else ‘t’ is printed. The argument given to the Boolean function in the above case is ‘spam’, which does not amount to zero. Hence the
output is: t. ]
Ans 5. d [ The code shown above returns a new list containing only those elements of the list l which do not amount to zero. Hence
the output is: [1, 2, ‘hello’] ]
Ans 6. b [ bool() always show True by default]
Ans 7. c [ 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. ]
Ans 8. d [ 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. ]
Ans 9. b [ 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. ]
Ans 10. b [ The expression not(10>20) returns True. The expression not(10<30) returns True. Hence the output is True. ]

Page 4 of 4 Computer Science 083 PYTHON [email protected]

You might also like