PCAP Exam QuestionsBrowse all questions from this exam

PCAP Exam - Question 120


What is the expected behavior of the following code?

Show Answer
Correct Answer: B

The code will raise a TypeError. The method 'make' in class 'Super' does not return a value, which means it implicitly returns 'None'. Therefore, 'b.doit()' will return 'None'. When trying to add 'a.doit()' which returns '1' to 'None', Python will raise a TypeError as it cannot perform addition between an integer and NoneType.

Discussion

4 comments
Sign in to comment
deckmanOption: B
May 14, 2022

B is the correct answer Traceback (most recent call last): File "main.py", line 17, in <module> print(a.doit() + b.doit()) TypeError: unsupported operand type(s) for +: 'int' and 'NoneType'

macxszOption: B
Apr 30, 2022

Outputs error. Int + NoneType

Siva_2022Option: B
May 15, 2022

Option B is the correct answer

seaverickOption: B
Jan 23, 2024

#question 120 class Super: def make(self): pass def doit(self): return self.make() class Sub_A(Super): def make(self): return 1 class Sub_B(Super): pass a=Sub_A() b=Sub_B() print(a.doit()) print(b.doit()) print(a.doit() + b.doit())#TypeError: unsupported operand type(s) for +: 'int' and 'NoneType' Tested: B. it raises an exception