πŸ“Š Problem Solving and Python Programming
Q. What is the output of the function complex()?
  • (A) 0j
  • (B) 0+0j
  • (C) 0
  • (D) error
πŸ’¬ Discuss
βœ… Correct Answer: (A) 0j

Explanation: the complex function returns 0j if both of the arguments are omitted, that is, if the function is in the form of complex() or complex(0), then the output will be 0j.

πŸ“Š Problem Solving and Python Programming
Q. The function divmod(a,b), where both ‘a’ and ‘b’ are integers is evaluated as:
  • (A) (a%b, a//b)
  • (B) (a//b, a%b)
  • (C) (a//b, a*b)
  • (D) (a/b, a%b)
πŸ’¬ Discuss
βœ… Correct Answer: (B) (a//b, a%b)

Explanation: the function divmod(a,b) is evaluated as a//b, a%b, if both ‘a’ and ‘b’ are integers.

πŸ“Š Problem Solving and Python Programming
Q. The function complex(‘2-3j’) is valid but the function complex(‘2 – 3j’) is invalid.
  • (A) true
  • (B) false
  • (C) ---
  • (D) ---
πŸ’¬ Discuss
βœ… Correct Answer: (A) true

Explanation: when converting from a string, the string must not contain any blank spaces around the + or – operator. hence the function complex(‘2 – 3j’) will result in an error.

πŸ“Š Problem Solving and Python Programming
Q. Which of the following functions does not necessarily accept only iterables as arguments?
  • (A) enumerate()
  • (B) all()
  • (C) chr()
  • (D) max()
πŸ’¬ Discuss
βœ… Correct Answer: (C) chr()

Explanation: the functions enumerate(), all() and max() accept iterables as arguments whereas the function chr() throws an error on receiving an iterable as an argument. also note that the function chr() accepts only integer values.

πŸ“Š Problem Solving and Python Programming
Q. Which of the following functions accepts only integers as arguments?
  • (A) ord()
  • (B) min()
  • (C) chr()
  • (D) any()
πŸ’¬ Discuss
βœ… Correct Answer: (C) chr()

Explanation: the function chr() accepts only integers as arguments. the function ord() accepts only strings. the functions min() and max() can accept floating point as well as integer arguments.

πŸ“Š Problem Solving and Python Programming
Q. Suppose there is a list such that: l=[2,3,4]. If we want to print this list in reverse order, which of the following methods should be used?
  • (A) reverse(l)
  • (B) list(reverse[(l)])
  • (C) reversed(l)
  • (D) list(reversed(l))
πŸ’¬ Discuss
βœ… Correct Answer: (D) list(reversed(l))

Explanation: the built-in function reversed() can be used to reverse the elements of a list. this function accepts only an iterable as an argument. to print the output in the form of a list, we use: list(reversed(l)). the output will be: [4,3,2].

πŸ“Š Problem Solving and Python Programming
Q. Which module in the python standard library parses options received from the command line?
  • (A) getopt
  • (B) os
  • (C) getarg
  • (D) main
πŸ’¬ Discuss
βœ… Correct Answer: (A) getopt

Explanation: getopt parses options received from the command line.

Jump to