Skip to content

Commit

Permalink
Merge pull request #746 from yest3a/my-documentation
Browse files Browse the repository at this point in the history
Added docstrings to some functions
  • Loading branch information
Mrinank-Bhowmick authored May 15, 2024
2 parents cddb477 + 4220358 commit a87366c
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 a87366c

Please sign in to comment.