Q 1. What will be the output of the following Python expression?
print(4.00/(2.0+2.0))
A. Error
B. 1.0
C. 1.00
D. 1
Show Answer
Answer:-B. 1.0Q 2. 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
Show Answer
Answer:-D. 27.2Explanation
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.Q 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
Show Answer
Answer:-C. 1.7 % 2Explanation
Explanation:- 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).
Q 4. 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)
Show Answer
Answer:-A. (1,3)Explanation
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.Q 5. Which among the following list of operators has the highest precedence?
+, -, **, %, /, <<, >>, |
A. <<, >>
B. **
C. |
D. %
Show Answer
Answer:-B. **Explanation
Explanation:- The highest precedence is that of the exponentiation operator, that is of **.Q 6. What will be the value of the following Python expression?
float(4+int(2.39)%2)
A. 5.0
B. 5
C. 4.0
D. 4
Show Answer
Answer:-C. 4.0Explanation
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.Q 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
Show Answer
Answer:-A. 4.0 + float(3)Explanation
Explanation:- Type conversion is nothing but explicit conversion of operands to a specific type. Options 5.3 + 6.3 and 5.0 + 3 are examples of implicit conversion whereas option 4.0 + float(3) is an example of explicit conversion or type conversion.Q 8. Which of the following expressions results in an error?
A. float(‘10’)
B. int(‘10’)
C. float(’10.8’)
D. int(’10.8’)
Show Answer
Answer:-D. int(’10.8’)Explanation
Explanation: All of the above examples show explicit conversion. However the expression int(’10.8’) results in an error.Q 9. What will be the value of the following Python expression?
4+2**5//10
A. 3
B. 7
C. 77
D. 0
Show Answer
Answer:-B. 7Explanation
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.Q 10. The expression 2**2**3 is evaluates as: (2**2)**3.
A. True
B. False
Leave a Reply