|
| 1 | +# custom_power: Lambda function |
| 2 | +custom_power = lambda x=0, e=1: x ** e |
| 3 | + |
| 4 | +# custom_equation: Function with detailed type annotations and docstring |
| 5 | +def custom_equation( |
| 6 | + x: int = 0, |
| 7 | + y: int = 0, |
| 8 | + a: int = 1, |
| 9 | + b: int = 1, |
| 10 | + *, c: int = 1 |
| 11 | +) -> float: |
| 12 | + """ |
| 13 | + Computes the value of the custom equation. |
| 14 | +
|
| 15 | + :param x: Positional-only integer, default is 0 |
| 16 | + :param y: Positional-only integer, default is 0 |
| 17 | + :param a: Positional-or-keyword integer, default is 1 |
| 18 | + :param b: Positional-or-keyword integer, default is 1 |
| 19 | + :param c: Keyword-only integer, default is 1 |
| 20 | + :return: Float result of the equation (x**a + y**b) / c |
| 21 | + """ |
| 22 | + return (x**a + y**b) / c |
| 23 | + |
| 24 | +# fn_w_counter: Function with call counting and caller tracking |
| 25 | +def fn_w_counter(): |
| 26 | + """ |
| 27 | + Counts the number of times this function is called, |
| 28 | + keeping track of caller information. |
| 29 | +
|
| 30 | + :return: A tuple of the total number of calls (int) and |
| 31 | + a dictionary with caller names and their call counts. |
| 32 | + """ |
| 33 | + if not hasattr(fn_w_counter, "call_count"): |
| 34 | + fn_w_counter.call_count = 0 |
| 35 | + fn_w_counter.caller_dict = {} |
| 36 | + |
| 37 | + fn_w_counter.call_count += 1 |
| 38 | + caller = __name__ |
| 39 | + if caller not in fn_w_counter.caller_dict: |
| 40 | + fn_w_counter.caller_dict[caller] = 0 |
| 41 | + fn_w_counter.caller_dict[caller] += 1 |
| 42 | + |
| 43 | + return fn_w_counter.call_count, fn_w_counter.caller_dict |
| 44 | + |
| 45 | +# Örnek kullanımlar |
| 46 | +if __name__ == "__main__": |
| 47 | + # custom_power örnekleri |
| 48 | + print(custom_power(2)) # 2 |
| 49 | + print(custom_power(2, 3)) # 8 |
| 50 | + print(custom_power(2, e=2)) # 4 |
| 51 | + |
| 52 | + # custom_equation örnekleri |
| 53 | + print(custom_equation(2, 3)) # 5.0 |
| 54 | + print(custom_equation(2, 3, 2)) # 7.0 |
| 55 | + print(custom_equation(3, 5, a=2, b=3, c=4)) # 33.5 |
| 56 | + |
| 57 | + # fn_w_counter örnekleri |
| 58 | + for i in range(10): |
| 59 | + fn_w_counter() |
0 commit comments