MCQ : Operators expressions and python statements For NIELIT O Level Exam

Operators expressions and python statements For NIELIT O Level Exam

00:00:00

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# : 01 out of 20



What will be the output of the following Python code?

  i = 0  while i < 5:      print(i)      i += 1      if i == 3:          break  else:      print(0)

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

Explanation :
The else part is not executed if control breaks out of the loop.

What will be the output of the following Python code?

  i = 0  while i < 5:      print(i)      i += 1      if i == 3:          break  else:      print(0)

Question No# : 02 out of 20



What will be the output of the following Python code?

  x = "abcdef"  i = "a"  while i in x:      x = x[:-1]      print(i, end = " ")

Option A. i i i i i i
Option B. a a a a a a
Option C. a a a a a
Option D. none of the mentioned
True Answer B

Explanation :
The string x is being shortened by one character in each iteration.

What will be the output of the following Python code?

  x = "abcdef"  i = "a"  while i in x:      x = x[:-1]      print(i, end = " ")

Question No# : 03 out of 20



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

  x = 'abcd'  for i in range(len(x)):      i.upper()  print (x)

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

Explanation :
Objects of type int have no attribute upper().

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

  x = 'abcd'  for i in range(len(x)):      i.upper()  print (x)

Question No# : 04 out of 20



What will be the output of the following Python code?

for i in range(int(float('inf'))):      print (i)

Option A. 0.0 0.1 0.2 0.3 …
Option B. 0 1 2 3 …
Option C. 0.0 1.0 2.0 3.0 …
Option D. none of the mentioned
True Answer D

Explanation :
OverflowError, cannot convert float infinity to integer.

What will be the output of the following Python code?

for i in range(int(float('inf'))):      print (i)

Question No# : 05 out of 20



What is the output of this expression, 3*1**3?

Option A. 27
Option B. 9
Option C. 3
Option D. 1
True Answer C

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

What is the output of this expression, 3*1**3?

Question No# : 06 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# : 07 out of 20



In Python, a variable may be assigned a value of one type, and then later assigned a value of a different type. This concept is known as

Option A. mutability
Option B. static typing
Option C. dynamic typing
Option D. immutability
True Answer C

Explanation :

In Python, a variable may be assigned a value of one type, and then later assigned a value of a different type. This concept is known as

Question No# : 08 out of 20



To increase the value of x five times using an augmented assignment operator, the correct expression will be

Option A. x += 5
Option B. x *= 5
Option C. x = x ** 5
Option D. none of these
True Answer B

Explanation :

To increase the value of x five times using an augmented assignment operator, the correct expression will be

Question No# : 09 out of 20



What will be the output of the following Python code?

  i = 2  while True:      if i%3 == 0:          break      print(i)      i += 2

Option A. 2 4 6 8 10 …
Option B. 2 4
Option C. 2 3
Option D. error
True Answer B

Explanation :
The numbers 2 and 4 are printed. The next value of i is 6 which is divisible by 3 and hence control exits the loop.

What will be the output of the following Python code?

  i = 2  while True:      if i%3 == 0:          break      print(i)      i += 2

Question No# : 10 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# : 11 out of 20



What will be the output of the following Python code?

    x = "abcdef"  while i in x:      print(i, end=" ")

Option A. a b c d e f
Option B. abcdef
Option C. i i i i i i …
Option D. error
True Answer D

Explanation :
NameError, i is not defined.

What will be the output of the following Python code?

    x = "abcdef"  while i in x:      print(i, end=" ")

Question No# : 12 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(d[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 D

Explanation :
Causes a KeyError.

What will be the output of the following Python code?

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

Question No# : 13 out of 20



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# : 14 out of 20



What will be the output of the following Python code?

    d = {0: 'a', 1: 'b', 2: 'c'}    for x in d.keys():        print(d[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 keys and prints the values.

What will be the output of the following Python code?

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

Question No# : 15 out of 20



What will be the output of the following Python code?

  x = 'abcd'  for i in x:      print(i.upper())

Option A. a b c d
Option B. A B C D
Option C. a B C D
Option D. error
True Answer B

Explanation :
The instance of the string returned by upper() is being printed.

What will be the output of the following Python code?

  x = 'abcd'  for i in x:      print(i.upper())

Question No# : 16 out of 20



What will be the value of X in the following Python expression?

X = 2+9*((3*12)-8)/10

Option A. 30.0
Option B. 30.8
Option C. 28.4
Option D. 27.2
True 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.

What will be the value of X in the following Python expression?

X = 2+9*((3*12)-8)/10

Question No# : 17 out of 20



What will be the output of the following Python code?

  x = "abcdef"  i = "a"  while i in x[:-1]:      print(i, end = " ")

Option A. a a a a a
Option B. a a a a a a
Option C. a a a a a a …
Option D. a
True Answer C

Explanation :
String x is not being altered and i is in x[:-1].

What will be the output of the following Python code?

  x = "abcdef"  i = "a"  while i in x[:-1]:      print(i, end = " ")

Question No# : 18 out of 20



Which of the following is not an immutable type in Python ?

Option A. String
Option B. Tuples
Option C. Set
Option D. None of these
True Answer C

Explanation :

Which of the following is not an immutable type in Python ?

Question No# : 19 out of 20



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

  x = 'abcd'  for i in range(len(x)):      i[x].upper()  print (x)

Option A. abcd
Option B. ABCD
Option C. error
Option D. none of the mentioned
True Answer C

Explanation :
Objects of type int aren’t subscriptable. However, if the statement was x[i], an error would not have been thrown.

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

  x = 'abcd'  for i in range(len(x)):      i[x].upper()  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