Skip to content

Commit

Permalink
Added docstrings to dome functions
Browse files Browse the repository at this point in the history
  • Loading branch information
yest3a committed May 14, 2024
1 parent 10ac2b2 commit 4220358
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions projects/Calculator/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,25 @@ def average():


def factorial(num):
"""
Function to calculate the factorial of a number.
Takes a number as an argument, calculates the factorial of the number,
and returns the result.
"""
answer = 1
for i in range(num):
answer *= i + 1
return answer


def complex_arithmetic():
"""
Function to execute complex arithmetic operations such as addition, subtraction, multiplication, and division.
Asks the user to choose the operation and input the complex numbers as real and imaginary parts,
performs the operation, and returns the result.
"""
print("Enter '1' for complex addition")
print("Enter '2' for complex subtraction")
print("Enter '3' for complex multiplication")
Expand Down Expand Up @@ -118,6 +130,12 @@ def complex_arithmetic():


def binomial(num):
"""
Function to calculate the binomial coefficient.
Takes two numbers as arguments, calculates the binomial coefficient using the formula n!/(k!(n-k)!),
and returns the result.
"""
result = factorial(num[0]) / (factorial(num[1]) * factorial(num[0] - num[1]))
return result

Expand Down

0 comments on commit 4220358

Please sign in to comment.