Test Series - python

Test Number 2/108

Q: Which is the correct operator for power(xy)?
A. X^y
B. X**y
C. X^^y
D. None of the mentioned
Solution: In python, power operator is x**y i.e. 2**3=8.
Q: Which one of these is floor division?
A. /
B. //
C. %
D. None of the mentioned
Solution: When both of the operands are integer then python chops out the fraction part and gives you the round off value, to get the accurate answer use floor division. This is floor division. For ex, 5/2 = 2.5 but both of the operands are integer so answer of this expression in python is 2. To get the 2.5 answer, use floor division.
Q: What is the order of precedence in python?
i) Parentheses
ii) Exponential
iii) Multiplication
iv) Division
v) Addition
vi) Subtraction
A. i,ii,iii,iv,v,vi
B. ii,i,iii,iv,v,vi
C. ii,i,iv,iii,v,vi
D. i,ii,iii,iv,vi,v
Solution: For order of precedence, just remember this PEMDAS (similar to BODMAS).
Q: What is the answer to this expression, 22 % 3 is?
A. 7
B. 1
C. 0
D. 5
Solution: Modulus operator gives the remainder. So, 22%3 gives the remainder, that is, 1.
Q: Mathematical operations can be performed on a string.
A. True
B. False
C. ...
D. ...
Solution: You can’t perform mathematical operation on string even if the string is in the form: ‘1234…’.
Q: Operators with the same precedence are evaluated in which manner?
A. Left to Right
B. Right to Left
C. Can’t say
D. None of the mentioned
Solution: None.
Q: What is the output of this expression, 3*1**3?
A. 27
B. 9
C. 3
D. 1
Solution: First this expression will solve 1**3 because exponential has higher precedence than multiplication, so 1**3 = 1 and 3*1 = 3. Final answer is 3.
Q: Which one of the following has the same precedence level?
A. Addition and Subtraction
B. Multiplication, Division and Addition
C. Multiplication, Division, Addition and Subtraction
D. Addition and Multiplication
Solution: “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.
Q: The expression Int(x) implies that the variable x is converted to integer.
A. True
B. False
C. ...
D. ...
Solution: None.
Q: Which one of the following has the highest precedence in the expression?
A. Exponential
B. Addition
C. Multiplication
D. Parentheses
Solution: Just remember: PEMDAS, that is, Parenthesis, Exponentiation, Division, Multiplication, Addition, Subtraction. Note that the precedence order of Division and Multiplication is the same. Likewise, the order of Addition and Subtraction is also the same.

You Have Score    /10