In what concerns the continuous evaluation solving exercises grade during the semester, you should submit until 23:59 of January 4th
(this exercise will still be available for submission after that deadline, but without counting towards your grade)
[to understand the context of this problem, you should read the class #11 exercise sheet]
In this problem you should submit a function as described. Inside the function do not print anything that was not asked!
At the end of the hallway, standing in the shadows, the man who once wore the suit of power—Agent Smith—waits.
"So, Mr. Anderson… You've learned much, haven't you? But do you truly understand the nature of this place?"
"I know you're behind all of this, Smith. Your system is flawed.", Neo replies.
Agent Smith, standing tall with his cold, menacing gaze, responds with a sneer -- "You still don't understand, Mr. Anderson. Your world is nothing more than a series of nested exceptions. Each decision, every step you take, triggers another. Let me show you."
Write a Python function nested_exceptions(tree) that, given a tree of functions in the form of a nested tuple tree where each element is a function, returns a tree with the same structure containing True
if the function raises an exception or False
otherwise.
For instance:
nested_exceptions((lambda: 1/0, lambda: 0))
returns the tuple (True, False)
nested_exceptions((lambda: 1/0, (lambda: 0, lambda: 1/0)))
returns the tuple (True, (False, True))
callable()
.
The following limits are guaranteed in all the test cases that will be given to your program:
f | A function that might raise an exception | |
0 ≤ |tree| ≤ 100 | Size of the input tuple tree and subtrees |
Example Function Calls | Example Output |
print(nested_exceptions((lambda: 1/0, lambda: 0))) print(nested_exceptions((lambda: 1/0, (lambda: 0, lambda: 1/0)))) |
(True, False) (True, (False, True)) |