PCPP-32-101 · Question #5
Analyze the following function and choose the statement that best describes it.
The correct answer is D. The function is erroneous. If you run this code to decorator a new function, you will get name error, regardless the colon in line 3 is missing or not. NameError: name 'level2_warpper' is not defined. This is because our_function (line 4) and my_function(line 2) did not return the SAME function line 2…
Question
Analyze the following function and choose the statement that best describes it.
Exhibit
Options
- AIt is an example of a decorator that accepts its own arguments.
- BIt is an example of decorator stacking.
- CIt is an example of a decorator that can trigger an infinite recursion
- DThe function is erroneous.
How the community answered
(41 responses)- A10% (4)
- B20% (8)
- C5% (2)
- D66% (27)
Explanation
If you run this code to decorator a new function, you will get name error, regardless the colon in line 3 is missing or not. NameError: name 'level2_warpper' is not defined. This is because our_function (line 4) and my_function(line 2) did not return the SAME function line 2: def level1_wrapper(my_function) line 4: return our_function To make this code correct, you can make FUNCTION_NAME in line 2 and line 4 consistency. eg. line 4 should be 'return my_function'.
Topics
Community Discussion
No community discussion yet for this question.
