Python Quiz-10

Q1. What will be the output of the following code:

  1. 8
  2. 9
  3. 10
  4. Error!

Answer: 2
Explanation: In Python language, len() function gives the length of an object. When the object is a string, it will output the number characters in the string.

Q2. What will be the output of following code:

  1. 5
  2. 6
  3. 5.14
  4. 7

Answer: 2
Explanation: => print(func3(2))
=> return math.ceil(func1(2)+func2(2))
=> return math.ceil(2*2+math.sqrt(2))
=> return math.ceil(4+1.414)
=> return math.ceil(5.414)
=> return 6
=> 6

Q3. What will be the output of following code:

  1. {‘a’: 1, ‘b’: 2, ‘c’: 3}
  2. {‘c’: 3}
  3. {‘a’: 1, ‘b’: 2}
  4. TypeError

Answer: 4
Explanation: D.popitem() -> (k, v), remove and return some (key, value) pair as a 2-tuple. But in this question only one argument is given to popitem() method.

Q4. Which of the following statements is not true?

  1. We can change the value of a private variable of superclass in the subclass
  2. Superclass non-private method can be overridden.
  3. The constructor of a class in invoked automatically.
  4. A derived class is a subclass of superclass

Answer: 1
Explanation: We can not change the value of a private variable of superclass in the subclass.

Q5. What type of error will be raised when the imported module is not found?

  1. ImportError
  2. NullPointerError
  3. NameError
  4. IndexNotFoundError

Answer: 1
Explanation: ImportError will be raised when the imported module is not found.

Q6. How does Python treat a string literal when it is not assigned to any variable?

  1. It will ignore the string literal.
  2. It will automatically assings a variable to it.
  3. It will through an error.
  4. None of the above.

Answer: 1
Explanation: In Python language, if you do not assign a string literal to a variable, it will ignore the string literal while in other languages like Java it will throw a compile time error.

Q7. In Python, which of the following variable is not of a integer data type?

  1. x = 435757438
  2. x = 5
  3. x = 23.45
  4. x = -5

Answer: 3
Explanation: Int is a whole number, it can be either positive or negative. It can not have decimal values also it can be of unlimited length.

Q8. Which of the following statement will extract the percentage of the mentioned student?

  1. print(data[‘school’][‘student’][‘result’][‘percentage’])
  2. print(data[‘School’][‘student’][‘result’][‘percentage’])
  3. print(data[‘School’][‘student’][‘result’][0])
  4. print(data[‘Sschool’][‘student’][0][‘percentage’])

Answer: 2
Explanation: json.loads() method can be used to parse a valid JSON string and convert it into a Python Dictionary.
json.loads() in Python
=> print(data[‘School’][‘student’][‘result’][‘percentage’])
=> 70%

Leave a Reply