File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import inspect
2+
3+ # A short function to calculate x to the power of e.
4+ custom_power = lambda x = 0 , / , e = 1 : x ** e
5+
6+ # Calculate the equation using the given numbers.
7+ def custom_equation (
8+ x : int = 0 ,
9+ y : int = 0 ,
10+ / ,
11+ a : int = 1 ,
12+ b : int = 1 ,
13+ * ,
14+ c : int = 1 ,
15+ ) -> float :
16+ """Calculate the sum of two powers divided by a coefficient.
17+
18+ :param x: First base.
19+ :type x: int
20+ :param y: Second base.
21+ :type y: int
22+ :param a: Exponent of the first base.
23+ :type a: int
24+ :param b: Exponent of the second base.
25+ :type b: int
26+ :param c: Divisor (must not be zero).
27+ :type c: int
28+ :returns: The result of (x**a + y**b) / c.
29+ :rtype: float
30+ :raises ZeroDivisionError: If c is zero.
31+ """
32+ # Divide the sum of the powers by c.
33+ return (x ** a + y ** b ) / c
34+
35+ def fn_w_counter () -> tuple [int , dict [str , int ]]:
36+ """Return total number of calls and counts by caller name."""
37+ # Find the function that called this one.
38+ caller_name = inspect .currentframe ().f_back .f_code .co_name
39+ # Update the total count and the count for this caller.
40+ fn_w_counter .count += 1
41+ fn_w_counter .callers [caller_name ] = fn_w_counter .callers .get (caller_name , 0 ) + 1
42+ # Return a copy so the saved counts do not change outside.
43+ return fn_w_counter .count , fn_w_counter .callers .copy ()
44+
45+ # Starting values for the counters.
46+ fn_w_counter .count = 0
47+ fn_w_counter .callers = {}
You can’t perform that action at this time.
0 commit comments