CS FundamentalsHardProduct-company placement

What does this Chain of Responsibility code print?

What does this Chain of Responsibility code print?
class Handler:
    def __init__(self, limit, name, nxt=None):
        self.limit, self.name, self.nxt = limit, name, nxt
    def handle(self, amt):
        if amt <= self.limit:
            return self.name
        if self.nxt:
            return self.nxt.handle(amt)
        return "rejected"
chain = Handler(1000, "clerk", Handler(10000, "manager", Handler(50000, "director")))
print([chain.handle(x) for x in (1000, 1001, 50000, 50001)])
  1. A. ['clerk', 'manager', 'director', 'rejected']
  2. B. ['manager', 'manager', 'director', 'director']
  3. C. ['clerk', 'manager', 'rejected', 'rejected']
  4. D. ['clerk', 'clerk', 'director', 'rejected']

Correct answer: A. ['clerk', 'manager', 'director', 'rejected']

Each handler takes amounts up to and including its limit and otherwise passes the request on. 1000 stops at the clerk, 1001 at the manager, 50000 at the director, and 50001 falls off the end of the chain.

More Software Engineering, Git and Cloud Basics questions

Exams that ask this topic