What is the expected behavior of the following code?
What is the expected behavior of the following code?
C
It raises an exception because there is no colon after Sub_B(Super)
I guess there's a Typo Error. A Syntax error is not an Exception (you cannot do try: except on that).
Sorry but it is. issubclass(SyntaxError, Exception) --> True
If text were right, answer is: B. it outputs 1 Otherwise it raises an exception because it has a typo.
Answer is B. Infuriating to see that just missing a colon and whoever wrote this assume code is wrong.. >>> class Super: def make(self): return 0 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() + b.doit())
Always is C. You can fix "class SubB(Super):" and see the result in question nº 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() + b.doit()) TypeError: unsupported operand type(s) for +: 'int' and 'NoneType'
If text were right, answer is: B. it outputs 1
One thing I've learned from doing these is to process like python does and check for syntax errors before doing anything else
#question 93 class Super: def make (self): return 0 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() + b.doit()) Tested, right answer C (it raises an exception)
>>> class Super: ... def make(self): ... return 0 ... 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() + b.doit()) 1 >>>
There are no indentation or typo issues in the exam!!!
did you pass the exam ?
Another question with a possible typo! Without the typo the answer is B.