Sobes.tech
Junior — Senior

@trace decorator that outputs a message about the start of a method call

livecode

Task condition

Create a decorator @trace that, upon each call of any method of an instance of the Person class, writes to the standard output a string of the form: Entering function <method_name>

Example behavior:

  • When calling the speak() method, a message should appear: Entering function speak
  • When calling the walk() method, a message should appear: Entering function walk
class Person:
    def __init__(self, person_name):
        self.person_name = person_name
        self.total_distance = 0

    @trace
    def speak(self, sentence):
        print(f'{self.person_name}: "{sentence}"')

    @trace
    def walk(self, distance):
        self.total_distance += distance
        print(f'{self.person_name}: total distance is {self.total_distance} meters')