πŸ“Š Problem Solving and Python Programming
Q. + '3'
  • (A) nameerror
  • (B) indexerror
  • (C) valueerror
  • (D) typeerror
πŸ’¬ Discuss
βœ… Correct Answer: (D) typeerror

Explanation: the line of code shown above will result in a type error. this is because the operand ‘+’ is not supported when we combine the data types ‘int’ and ‘str’. sine this is exactly what we have done in the code shown above, a type error is thrown.

πŸ“Š Problem Solving and Python Programming
Q. 43')
  • (A) importerror
  • (B) valueerror
  • (C) typeerror
  • (D) nameerror
πŸ’¬ Discuss
βœ… Correct Answer: (B) valueerror

Explanation: the snippet of code shown above results in a value error. this is because there is an invalid literal for int() with base 10: ’65.43’.

πŸ“Š Problem Solving and Python Programming
Q. >>>list("a#b#c#d".split('#'))
  • (A) [‘a’, ‘b’, ‘c’, ‘d’]
  • (B) [‘a b c d’]
  • (C) [‘a#b#c#d’]
  • (D) [‘abcd’]
πŸ’¬ Discuss
βœ… Correct Answer: (A) [‘a’, ‘b’, ‘c’, ‘d’]

Explanation: execute in the shell to verify.

πŸ“Š Problem Solving and Python Programming
Q. What will be the output of the following
Python code?
>>> str1 = 'hello'
>>> str2 = ','
>>> str3 = 'world'
>>> str1[-1:]
  • (A) olleh
  • (B) hello
  • (C) h
  • (D) o
πŸ’¬ Discuss
βœ… Correct Answer: (D) o

Explanation: -1 corresponds to the last index.

πŸ“Š Problem Solving and Python Programming
Q. What will be the output of the following Python code? >>>print('new' 'line')
  • (A) error
  • (B) output equivalent to print ‘new\\nline’
  • (C) newline
  • (D) new line
πŸ’¬ Discuss
βœ… Correct Answer: (C) newline

Explanation: string literal separated by whitespace are allowed. they are concatenated.

Jump to