

class Timer:

    def __enter__(self):
        pass

        



import time


class Timer:

    def __enter__(self):
        self.start = time.time()

    def __exit__(self, exc_type, exc_val, exc_tb):
        print("elapsed time:", time.time() - self.start)

Add enter and exit methods.
Add enter and exit methods.

+ 
+ 
+ import time
  
  
  class Timer:
  
      def __enter__(self):
-         pass
+         self.start = time.time()
  
-         
+     def __exit__(self, exc_type, exc_val, exc_tb):
+         print("elapsed time:", time.time() - self.start)
  
Add enter and exit methods.
## Code Before:


class Timer:

    def __enter__(self):
        pass

        

## Instruction:
Add enter and exit methods.
## Code After:


import time


class Timer:

    def __enter__(self):
        self.start = time.time()

    def __exit__(self, exc_type, exc_val, exc_tb):
        print("elapsed time:", time.time() - self.start)
