πŸ“Š Problem Solving and Python Programming
Q. In python we do not specify types, it is
directly interpreted by the compiler, so
consider the following operation to be
performed.
>>>x = 13 ? 2
objective is to make sure x has a integer
value, select all that apply (python 3.xx)
  • (A) x = 13 // 2
  • (B) x = int(13 / 2)
  • (C) x = 13 % 2
  • (D) all of the mentioned
πŸ’¬ Discuss
βœ… Correct Answer: (D) all of the mentioned

Explanation: // is integer operation in python

πŸ“Š Problem Solving and Python Programming
Q. what will be the output of the following
Python code snippet?
def example(a):
a = a + '2'
a = a*2
return a
>>>example("hello")
  • (A) indentation error
  • (B) cannot perform mathematical operation on strings
  • (C) hello2
  • (D) hello2hello2
πŸ’¬ Discuss
βœ… Correct Answer: (A) indentation error

Explanation: python codes have to be indented properly.

πŸ“Š Problem Solving and Python Programming
Q. In order to store values in terms of key and value we use what core data type.
  • (A) list
  • (B) tuple
  • (C) class
  • (D) dictionary
πŸ’¬ Discuss
βœ… Correct Answer: (D) dictionary

Explanation: dictionary stores values in terms of keys and values.

πŸ“Š Problem Solving and Python Programming
Q. Which of the following results in a SyntaxError?
  • (A) ‘”once upon a time…”, she said.’
  • (B) “he said, ‘yes!\”
  • (C) ‘3\\’
  • (D) ”’that’s okay”’
πŸ’¬ Discuss
βœ… Correct Answer: (C) ‘3\\’

Explanation: carefully look at the colons.

πŸ“Š Problem Solving and Python Programming
Q. What is the average value of the
following Python code snippet?
>>>grade1 = 80
>>>grade2 = 90
>>>average = (grade1 + grade2) / 2
  • (A) 85.0
  • (B) 85.1
  • (C) 95.0
  • (D) 95.1
πŸ’¬ Discuss
βœ… Correct Answer: (A) 85.0

Explanation: cause a decimal value of 0 to appear as output.

πŸ“Š Problem Solving and Python Programming
Q. What is the output of print 0.1 + 0.2 == 0.3?
  • (A) true
  • (B) false
  • (C) machine dependent
  • (D) error
πŸ’¬ Discuss
βœ… Correct Answer: (B) false

Explanation: neither of 0.1, 0.2 and 0.3 can be represented accurately in binary. the round off errors from 0.1 and 0.2 accumulate and hence there is a difference of 5.5511e-17 between (0.1 + 0.2) and 0.3.

πŸ“Š Problem Solving and Python Programming
Q. What is the type of inf?
  • (A) boolean
  • (B) integer
  • (C) float
  • (D) complex
πŸ’¬ Discuss
βœ… Correct Answer: (C) float

Explanation: infinity is a special case of floating point numbers. it can be obtained by float(‘inf’).

Jump to