# bk.py import inspect import copy _last_vars = {} def break_and_show(): """ Represents a breakpoint. It shows the old and new values of variables that have changed since the last breakpoint or the beginning of the program. Variables with names starting with an underscore are ignored. It also shows the line number of the call of the function. """ global _last_vars # Get the calling frame (f_back) frame = inspect.currentframe().f_back # Get the line number of the call line_info = inspect.getframeinfo(frame) print("--------------------------------------") print(f"-- Breakpoint at line: {line_info.lineno}") current_vars = { name: value for name, value in frame.f_locals.items() if not name.startswith('_') } changed_vars = {} for name, value in current_vars.items(): if name not in _last_vars or _last_vars[name] != value: old_value = _last_vars.get(name, "N/A (new variable)") changed_vars[name] = {"old": old_value, "new": value} if changed_vars: print("-- Changed variables:") for name, values in changed_vars.items(): print(f"-- {name}: {values['old']} -> {values['new']}") else: print("No variables have changed.") print("--------------------------------------") _last_vars = copy.deepcopy(current_vars) if __name__ == "__main__": age = 21 if age >= 18: print("You may vote.") break_and_show() predicted_value = 0.85 threshold = 0.7 if predicted_value >= threshold: prediction_outcome = "Positive" else: prediction_outcome = "Negative" print(f"Prediction outcome: {prediction_outcome}") break_and_show()