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: 'a', 1: 'b', 2: 'c'}  for x, y in d.items():      print(x, y)

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 C

Explanation :
Loops over key, value pairs.

What will be the output of the following Python code?

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

Question No# : 01 out of 20



Which statement is generally used as a placeholder?

Option A. continue
Option B. break
Option C. pass
Option D. goto
True Answer C

Explanation :

Which statement is generally used as a placeholder?

Question No# : 02 out of 20

What will be the output of the following Python code?

True = False  while True:      print(True)      break

Option A. True
Option B. False
Option C. None
Option D. none of the mentioned
True Answer D

Explanation :
SyntaxError, True is a keyword and it’s value cannot be changed.

What will be the output of the following Python code?

True = False  while True:      print(True)      break

Question No# : 03 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# : 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



The continue and break statement have same effect

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

Explanation :

The continue and break statement have same effect

Question No# : 06 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. a a a a a a
Option B. a
Option C. no output
Option D. error
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# : 07 out of 20



elif can be considered to be abbreviation of

Option A. nested if
Option B. if..else
Option C. else if
Option D. if..elif
True Answer C

Explanation :

elif can be considered to be abbreviation of

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



Which of the following is not Logical operator?

Option A. and
Option B. or
Option C. not
Option D. Assignment
True Answer D

Explanation :

Which of the following is not Logical operator?

Question No# : 11 out of 20

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

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

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

Explanation :
abcd a a a is the output as x is modified only after ‘abcd’ has been printed once.

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

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

Question No# : 12 out of 20



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

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

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

Explanation :
The value of a[0] changes in each iteration. Since the first value that it takes is itself, there is no visible error in the current example.

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

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

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



What will be the output of the following Python code?

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

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

Explanation :
The else part is executed when the condition in the while statement is false.

What will be the output of the following Python code?

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

Question No# : 15 out of 20



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

not(10<20) and not(10>30)

Option A. True
Option B. False
Option C. Error
Option D. No output
True Answer B

Explanation :
The expression not(10<20) returns false. The expression not(10>30) returns true. The and operation between false and true returns false. Hence the output is false.

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

not(10<20) and not(10>30)

Question No# : 16 out of 20



What will be the output of the following Python code?

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

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

Explanation :
As the value of i or x isn’t changing, the condition will always evaluate to True.

What will be the output of the following Python code?

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

Question No# : 17 out of 20



What will be the output of the following Python code?

string = "my name is x"  for i in string:      print (i, end=", ")

Option A. m, y, , n, a, m, e, , i, s, , x,
Option B. m, y, , n, a, m, e, , i, s, , x
Option C. my, name, is, x,
Option D. error
True Answer A

Explanation :
Variable i takes the value of one character at a time.

What will be the output of the following Python code?

string = "my name is x"  for i in string:      print (i, end=", ")

Question No# : 18 out of 20



Which of the following Boolean expressions is not logically equivalent to the other three?

Option A. not(-6<0 or-6>10)
Option B. -6>=0 and -6<=10
Option C. not(-6<10 or-6==10)
Option D. not(-6>10 or-6==10)
True Answer D

Explanation :
The expression not(-6<0 or -6>10) returns the output False. The expression -6>=0 and -6<=10 returns the output False. The expression not(-6<10 or -6==10) returns the output False. The expression not(-6>10 or -6==10) returns the output True.

Which of the following Boolean expressions is not logically equivalent to the other three?

Question No# : 19 out of 20



What is the answer to this expression, 22 % 3 is?

Option A. 7
Option B. 1
Option C. 0
Option D. 5
True Answer B

Explanation :
Modulus operator gives the remainder. So, 22%3 gives the remainder, that is, 1.

What is the answer to this expression, 22 % 3 is?

Question No# : 20 out of 20