Debugging and testing · 6 / 14 Exercise Medium

Read a traceback

Objective

Create a Python program that extracts the important information from a traceback, the message that Python shows when an exception is not caught.

Instructions

  • Read an integer n and then n lines of a simplified traceback. All but the last one have the format File "name", line N, in function. The last one is the error: Type: message (or just Type if there is no message).
  • The error happened on the last File line (the innermost one). To separate its parts, use split(", ").
  • Show four lines: Exception: Type, Message: text (or Message: - if there is none), Line: N and Function: name.
  • Show a fifth line, Calls: K, with the number of File lines.
Input
3
File "main.py", line 10, in <module>
File "main.py", line 4, in dividir
ZeroDivisionError: division by zero
Output
Exception: ZeroDivisionError
Message: division by zero
Line: 4
Function: dividir
Calls: 2

Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.

Start exercise