LearnPy Hub
← Context Managers problems
Hard

Profile Sections With a Fake Clock

A fake clock returns the next number from the input list each time clock() is called. Write a @contextmanager section(name) that reads the clock on entry and exit, nests (keep a stack of names), and records the elapsed time under the full path like main/load. Run the commands enter NAME / exit using recursion so each enter opens a with section(NAME) block. Print each path with its total time, in the order the sections finished.

Input

Clock readings on one line, then commands, then END.

Output

Lines.

Sample 1

Input
0 1 4 5 9 10
enter main
enter load
exit
enter train
exit
exit
END
Output
main/load 3
main/train 4
main 10

Sample 2

Input
3 8
enter only
exit
END
Output
only 5
solution.py
Output appears here
Profile Sections With a Fake Clock · Python practice problem · LearnPy Hub