Skip to content
Open
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
18 changes: 8 additions & 10 deletions src/arithmetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,19 @@ def subtract(a: int | float, b: int | float) -> int | float:
return a - b


def multiply(a: int | float, b: int | float) -> int | float:
"""Multiply two numbers."""
return a * b
def multiply_or_power(a:int|float, b: int|float, power:bool=False)-> int|float:
"""Multiply two numbers or raise a to the power of b."""
if power: return a**b
return a*b


def divide(a: int | float, b: int | float) -> float:
"""Divide two numbers."""
return a / b


def power(a: int | float, b: int | float) -> int | float:
"""Raise a to the power of b."""
raise NotImplementedError("power is not implemented yet")


def factorial(n: int) -> int:
def factorial(n:int)->int:
"""Calculate the factorial of n."""
raise NotImplementedError("factorial is not implemented yet")
if n==0: return 1
elif n<0: raise ValueError("Factorial is not defined for negative numbers.")
else: return n*factorial(n-1)