QUIZ ON : PROGRAMMING AND PROBLEM SOLVING THROUGH PYTHON - OPERATORS EXPRESSIONS AND PYTHON STATEMENTS

OPERATORS EXPRESSIONS AND PYTHON STATEMENTS

00:00:00

What will be the output of the following Python code?

  d = {0, 1, 2}  for x in d:      print(d.add(x))

Option A. 0 1 2
Option B. 0 1 2 0 1 2 0 1 2 …
Option C. None None None
Option D. None of the mentioned
True Answer C

Explanation :
Variable x takes the values 0, 1 and 2. set.add() returns None which is printed.

What will be the output of the following Python code?

  d = {0, 1, 2}  for x in d:      print(d.add(x))

Question No# : 01 out of 20



What will be the output of the following Python expression?

24//6%3, 24//4//2

Option A. (1,3)
Option B. (0,3)
Option C. (1,0)
Option D. (3,1)
True 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.

What will be the output of the following Python expression?

24//6%3, 24//4//2

Question No# : 02 out of 20



We cannot write a loop that can execute forever.

Option A. TRUE
Option B. FALSE
Option C.
Option D.
True Answer B

Explanation :

We cannot write a loop that can execute forever.

Question No# : 03 out of 20

What will be the output of the following Python code?

for i in range(int(2.0)):      print(i)

Option A. 0.0 1.0
Option B. 0 1
Option C. error
Option D. none of the mentioned
True Answer B

Explanation :
range(int(2.0)) is the same as range(2).

What will be the output of the following Python code?

for i in range(int(2.0)):      print(i)

Question No# : 04 out of 20



What will be the output of the following Python code snippet?

for i in 'abcd'[::-1]:      print (i)

Option A. a b c d
Option B. d c b a
Option C. error
Option D. none of the mentioned
True Answer B

Explanation :
[::-1] reverses the string.

What will be the output of the following Python code snippet?

for i in 'abcd'[::-1]:      print (i)

Question No# : 05 out of 20



What will be the output of the following Python code snippet?

not(3>4)
not(1&1)

Option A. True True
Option B. True False
Option C. False True
Option D. False False
True Answer B

Explanation :
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.

What will be the output of the following Python code snippet?

not(3>4)
not(1&1)

Question No# : 06 out of 20



Which one of these is floor division?

Option A. /
Option B. //
Option C. %
Option D. None of the mentioned
True Answer B

Explanation :
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.

Which one of these is floor division?

Question No# : 07 out of 20



Which is the correct operator for power(x,y)?

Option A. X^y
Option B. X**y
Option C. X^^y
Option D. None of the mentioned
True Answer B

Explanation :
In python, power operator is x**y i.e. 2**3=8.

Which is the correct operator for power(x,y)?

Question No# : 08 out of 20



What will be the output of the following Python code?

for i in range(2.0):      print(i)

Option A. 0.0 1.0
Option B. 0 1
Option C. error
Option D. none of the mentioned
True Answer C

Explanation :
Object of type float cannot be interpreted as an integer.

What will be the output of the following Python code?

for i in range(2.0):      print(i)

Question No# : 09 out of 20



What will be the output of the following Python code?

  x = ['ab', 'cd']  for i in x:      x.append(i.upper())  print(x)

Option A. [‘AB’, ‘CD’]
Option B. [‘ab’, ‘cd’, ‘AB’, ‘CD’]
Option C. [‘ab’, ‘cd’]
Option D. none of the mentioned
True Answer D

Explanation :
The loop does not terminate as new elements are being added to the list in each iteration.

What will be the output of the following Python code?

  x = ['ab', 'cd']  for i in x:      x.append(i.upper())  print(x)

Question No# : 10 out of 20



What will be the output of the following Python code?

  x = (i for i in range(3))  for i in x:      print(i)  for i in x:      print(i)

Option A. 0 1 2
Option B. error
Option C. 0 1 2 0 1 2
Option D. none of the mentioned
True Answer A

Explanation :
We can loop over a generator object only once.

What will be the output of the following Python code?

  x = (i for i in range(3))  for i in x:      print(i)  for i in x:      print(i)

Question No# : 11 out of 20



Which one of the following has the highest precedence in the expression?

Option A. Exponential
Option B. Addition
Option C. Multiplication
Option D. Parentheses
True Answer D

Explanation :
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.

Which one of the following has the highest precedence in the expression?

Question No# : 12 out of 20



What will be the output of the following Python code snippet?

  a = [0, 1, 2, 3]  for a[-1] in a:      print(a[-1])

Option A. 0 1 2 3
Option B. 0 1 2 2
Option C. 3 3 3 3
Option D. error
True Answer B

Explanation :
The value of a[-1] changes in each iteration.

What will be the output of the following Python code snippet?

  a = [0, 1, 2, 3]  for a[-1] in a:      print(a[-1])

Question No# : 13 out of 20



What will be the output of the following Python code snippet?

for i in [1, 2, 3, 4][::-1]:      print (i)

Option A. 1 2 3 4
Option B. 4 3 2 1
Option C. error
Option D. none of the mentioned
True Answer B

Explanation :
[::-1] reverses the list.

What will be the output of the following Python code snippet?

for i in [1, 2, 3, 4][::-1]:      print (i)

Question No# : 14 out of 20



What will be the value of the following Python expression?

4+2**5//10

Option A. 3
Option B. 7
Option C. 77
Option D. 0
True 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.

What will be the value of the following Python expression?

4+2**5//10

Question No# : 15 out of 20



What will be the output of the following Python statement?

>>>"a"+"bc"

Option A. a
Option B. bc
Option C. bca
Option D. abc
True Answer D

Explanation :
+ operator is concatenation operator.

What will be the output of the following Python statement?

>>>"a"+"bc"

Question No# : 16 out of 20



Which operator is also called as Comparative operator?

Option A. Arithmetic
Option B. Relational
Option C. Logical
Option D. Assignment
True Answer B

Explanation :

Which operator is also called as Comparative operator?

Question No# : 17 out of 20



Which of the following expressions is an example of type conversion?

Option A. 4.0 + float(3)
Option B. 5.3 + 6.3
Option C. 5.0 + 3
Option D. 3 + 7
True Answer A

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.

Which of the following expressions is an example of type conversion?

Question No# : 18 out of 20



print(0xA + 0xB + 0xC):

Option A. 0xA0xB0xC
Option B. Error
Option C. 0x22
Option D. 33
True Answer D

Explanation :
0xA and 0xB and 0xC are hexadecimal integer literals representing the decimal values 10, 11 and 12 respectively. There sum is 33.

print(0xA + 0xB + 0xC):

Question No# : 19 out of 20



What will be the output of the following Python code?

  d = {0: 'a', 1: 'b', 2: 'c'}  for x in d.values():      print(x)

Option A. 0 1 2
Option B. a b c
Option C. 0 a 1 b 2 c
Option D. none of the mentioned
True Answer B

Explanation :
Loops over the values.

What will be the output of the following Python code?

  d = {0: 'a', 1: 'b', 2: 'c'}  for x in d.values():      print(x)

Question No# : 20 out of 20




CCC Online Test 2021 CCC Practice Test Hindi Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level NIELIT Study material and Quiz Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Sarkari Naukari Notification Best Website and Software Company in Allahabad Website development Company in Allahabad