11import inspect
2-
2+
33# x is positional-only (default 0), e is positional-or-keyword (default 1)
44custom_power = lambda x = 0 , / , e = 1 : x ** e
5-
6-
5+
6+
77def custom_equation (
88 x : int = 0 , y : int = 0 , / , a : int = 1 , b : int = 1 , * , c : int = 1
99) -> float :
1010 """
1111 Calculate (x**a + y**b) / c.
12-
12+
1313 :param x: Positional-only base of the first term.
1414 :type x: int
1515 :param y: Positional-only base of the second term.
@@ -24,16 +24,16 @@ def custom_equation(
2424 :rtype: float
2525 """
2626 return (x ** a + y ** b ) / c
27-
28-
27+
28+
2929_total_calls : int = 0
3030_calls_by_caller : dict [str , int ] = {}
31-
32-
33- def fn_w_counter () -> tuple [ int , dict [str , int ]] :
31+
32+
33+ def fn_w_counter () -> ( int , dict [str , int ]) :
3434 """
3535 Count how many times this function has been called, and by whom.
36-
36+
3737 :return: A tuple of the total number of calls and a dictionary mapping
3838 each caller's ``__name__`` to the number of calls it made.
3939 :rtype: tuple[int, dict[str, int]]
@@ -43,21 +43,21 @@ def fn_w_counter() -> tuple[int, dict[str, int]]:
4343 _total_calls += 1
4444 _calls_by_caller [caller ] = _calls_by_caller .get (caller , 0 ) + 1
4545 return _total_calls , dict (_calls_by_caller )
46-
47-
46+
47+
4848if __name__ == "__main__" :
4949 assert custom_power (2 ) == 2
5050 assert custom_power (2 , 3 ) == 8
5151 assert custom_power (2 , e = 2 ) == 4
52-
52+
5353 assert custom_equation (2 , 3 ) == 5.0
5454 assert custom_equation (2 , 3 , 2 ) == 7.0
5555 assert custom_equation (2 , 3 , 2 , 3 ) == 31.0
5656 assert custom_equation (3 , 5 , a = 2 , b = 3 , c = 4 ) == 33.5
5757 assert custom_equation (3 , 5 , 2 , b = 3 , c = 4 ) == 33.5
5858 assert custom_equation (3 , 5 , 2 , 3 , c = 4 ) == 33.5
59-
59+
6060 for i in range (10 ):
6161 fn_w_counter ()
6262 assert fn_w_counter () == (11 , {"__main__" : 11 })
63- print ("All examples pass." )
63+ print ("All examples pass." )
0 commit comments