0% found this document useful (0 votes)
30 views

Problem Solving 2

This document contains 13 multiple choice questions about operator precedence and order of operations in Python. Some key points covered include: - Exponentiation (**) has right-to-left associativity while other operators like +, -, *, / have left-to-right associativity. - Integer division (//) truncates the result while regular division (/) returns a float. - Explicit type conversions like int() and float() can alter the value of an expression. - Bracketing subexpressions can override default order of operations but not associativity.

Uploaded by

Blessing Chioma
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views

Problem Solving 2

This document contains 13 multiple choice questions about operator precedence and order of operations in Python. Some key points covered include: - Exponentiation (**) has right-to-left associativity while other operators like +, -, *, / have left-to-right associativity. - Integer division (//) truncates the result while regular division (/) returns a float. - Explicit type conversions like int() and float() can alter the value of an expression. - Bracketing subexpressions can override default order of operations but not associativity.

Uploaded by

Blessing Chioma
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Problem Solving and Python Programming

MCQs [set-1]

Chapter: Precedence of Operators

1. The value of the expressions 4/(3*(2-1)) and 4/3*(2-1) is the same.


A. true
B. false
Answer: A
Explanation:- 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.

o m
.
2. What will be the value of the following Pythoncexpression? 4 + 3 % 5
A. 4
te
B. 7 a
C. 2
q M
D. 0 c
Answer: B
M
Explanation:- the order of precedence is: %,+. Hence the expression above, on simplification results
in 4 + 3 = 7. Hence the result is 7.

3. Which of the following operators has its associativity from right to left?
A. +
B. //
C. %
D. **
Answer: D
Explanation:- all of the operators shown above have associativity from left to right, except
exponentiation operator (**) which has its associativity from right to left.

4. What will be the value of x in the


following Python expression?
x = int(43.55+2/2)
A. 43
B. 44
C. 22
D. 23
Answer: B
Explanation:- 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.

5. 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)
Answer: A
Explanation:- 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.

6. Which of the following is the truncation division operator?


A. /
B. %
C. //
Answer: C
Explanation:- // is the operator for truncation division. it is called so because it returns only the
integer part of the quotient, truncating the decimal part. for example: 20//3 = 6.

7. What are the values of the following


Python 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
Answer: D
Explanation:- 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

Download more sets at McqMate.com


associativity of ** operator is from right to left. Hence the result of the third expression is 512.

8. 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)
Answer: A
Explanation:- the above expressions are evaluated as: 2/2, 8/2, which is equal to (1.0, 4.0).

9. What will be the value of X in the


following Python expression?
X = 2+9*((3*12)-8)/10
A. 30.0
B. 30.8
C. 28.4
D. 27.2
Answer: D
Explanation:- 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.

10. What will be the output of the following


Python expression?
24//6%3, 24//4//2
A. (1,3)
B. (0,3)
C. (1,0)
D. (3,1)
Answer: A
Explanation:- 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.

11. What will be the value of the following


Python expression?
float(4+int(2.39)%2)
A. 5.0
B. 5

Download more sets at McqMate.com


C. 4.0
D. 4
Answer: C
Explanation:- 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.

12. What will be the value of the following


Python expression?
4+2**5//10
A. 3
B. 7
C. 77
D. 0
Answer: B
Explanation:- 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.

13. The expression 2**2**3 is evaluates as: (2**2)**3.


A. true
B. false
Answer: B
Explanation:- 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.

Download more sets at McqMate.com

You might also like