|
| 1 | +# Lambda function to compute x raised to the power e |
| 2 | +custom_power = lambda x=0, /, e=1: x**e |
| 3 | + |
| 4 | +def custom_equation(x: int = 0, y: int = 0, /, a: int = 1, b: int = 1, *, c: int = 1) -> float: |
| 5 | + """ |
| 6 | + Computes the equation (x**a + y**b) / c. |
| 7 | +
|
| 8 | + :param x: Base value for the first term (positional-only, defaults to 0). |
| 9 | + :param y: Base value for the second term (positional-only, defaults to 0). |
| 10 | + :param a: Exponent applied to x (default is 1). |
| 11 | + :param b: Exponent applied to y (default is 1). |
| 12 | + :param c: Divisor for the equation (keyword-only, default is 1). |
| 13 | + :return: The calculated result as a float. |
| 14 | + :raises ZeroDivisionError: If c equals 0. |
| 15 | + """ |
| 16 | + if c == 0: # Ensure we don't divide by zero |
| 17 | + raise ZeroDivisionError("Division by zero is not allowed.") |
| 18 | + |
| 19 | + return (x**a + y**b) / c # Compute the result |
| 20 | + |
| 21 | +def fn_w_counter() -> tuple[int, dict[str, int]]: |
| 22 | + """ |
| 23 | + Tracks the number of function calls and the caller's name. |
| 24 | +
|
| 25 | + :return: A tuple with the total call count and a dictionary mapping callers to their respective counts. |
| 26 | + """ |
| 27 | + # Initialize attributes if they don't exist |
| 28 | + if not hasattr(fn_w_counter, "call_count"): |
| 29 | + fn_w_counter.call_count = 0 # Total call count |
| 30 | + fn_w_counter.callers_dict = {} # Caller-specific counts |
| 31 | + |
| 32 | + # Increment total call count |
| 33 | + fn_w_counter.call_count += 1 |
| 34 | + |
| 35 | + # Identify the caller's module |
| 36 | + caller = __name__ |
| 37 | + |
| 38 | + # Update the caller's count |
| 39 | + if caller in fn_w_counter.callers_dict: |
| 40 | + fn_w_counter.callers_dict[caller] += 1 |
| 41 | + else: |
| 42 | + fn_w_counter.callers_dict[caller] = 1 |
| 43 | + |
| 44 | + return fn_w_counter.call_count, fn_w_counter.callers_dict |
0 commit comments