Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions Week04/functions_berra_soyler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from typing import Callable, Tuple, Dict
import inspect

custom_power: Callable[[int, int], int] = lambda x=0, e=1: x ** e
custom_power.__signature__ = inspect.Signature([
inspect.Parameter('x', inspect.Parameter.POSITIONAL_ONLY, default=0),
inspect.Parameter('e', inspect.Parameter.POSITIONAL_OR_KEYWORD, default=1)
])

def custom_equation(x: int = 0, y: int = 0, /, a: int = 1, b: int = 1, *, c: int = 1) -> float:
"""
Compute a custom equation.

:param x: An integer, positional-only, with default value 0
:param y: An integer, positional-only, with default value 0
:param a: An integer, positional-or-keyword, with default value 1
:param b: An integer, positional-or-keyword, with default value 1
:param c: An integer, keyword-only, with default value 1
:return: Result of (x**a + y**b) / c as a float
"""
return (x ** a + y ** b) / c

call_counter: Dict[str, int] = {}

def fn_w_counter() -> Tuple[int, Dict[str, int]]:
"""
Count the number of function calls and return caller information.

:return: A tuple containing the total number of calls and a dictionary with caller names as keys and call counts as values.
"""
caller = "__main__"
call_counter[caller] = call_counter.get(caller, 0) + 1
return call_counter[caller], call_counter
Loading