11. What is the output of the following code
x = 6
y = 2
print(x ** y)
print(x // y)
- 660
- 360
- 663
- 363
Answer : D Explanation: The Exponent (**) operator performs exponential (power) calculation. so here 6 ** 2 means 6*6 = 36 The // is the Floor Division operator so 6//2=3
12. What is the output of the following program :
i = 0
while i < 3:
print i
i++
print i+1
- 0 2 1 3 2 4
- 0 1 2 3 4 5
- Error
- 1 0 2 4 3 5
Answer : C Explanation: Python Programming language does not support ‘++’ operator.
13. Suppose the following statements are executed:
a = 100
b = 200
What is the value of the expression a and b?
- True
- 0
- False
- 200
- 100
Answer : D Explanation: None
14. Operators with the same precedence are evaluated in which manner?
- Left to Right
- Right to Left
- Can’t say
- None of the mentioned
Answer : A Explanation: None
15. Which of the following operators has the highest precedence?
- not
- &
- *
- +
Answer : C Explanation: None
16. Given a function that does not return any value, what value is shown when executed at the shell?
- int
- bool
- void
- None
Answer : D Explanation: Python explicitly defines the None object that is returned if no value is specified.
17. The function sqrt() from the math module computes the square root of a number. Will the highlighted line of code raise an exception?
x = -100
from math import sqrt
x > 0 and sqrt(x)
- Yes
- No
- void
- None
Answer : B Explanation: In the highlighted line, x > 0 is False. The expression is already known to be falsy at that point. Due to short-circuit evaluation, sqrt(x) (which would raise an exception) is not evaluated.
18. Which one of the following has the same precedence level?
- Addition and Subtraction
- Multiplication, Division and Addition
- Multiplication, Division, Addition and Subtraction
- Addition and Multiplication
Answer : A Explanation: “Addition and Subtraction” are at the same precedence level. Similarly, “Multiplication and Division” are at the same precedence level. However, Multiplication and Division operators are at a higher precedence level than Addition and Subtraction operators.
19. What is the output of the following code
print(bool(0), bool(3.14159), bool(-3), bool(1.0+1j))
- True True False True
- False True True True
- True True False True
- False True False True
Answer : B Explanation: If we pass A zero value to the bool() constructor, it will treat it as false. Any non-zero value is true.
20. What is the output of the expression print(-18 // 4)
- -4
- -5
- 4
- 5
Answer : B Explanation: In the case of the floor division operator(//), when the result is negative, the result is rounded down to the next smallest (big negative) integer.