Skip to content

Commit 0315c4c

Browse files
Added an new function called "average" (#37)
* hacktoberfest contribution
1 parent ac5f9bb commit 0315c4c

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

-2 Bytes
Binary file not shown.

easyPythonpi/easyPythonpi.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,30 @@ def sub(x:'float', y:'float')->'float': # For substraction of 2 numbers
1515
def multi(x:'float', y:'float')->'float': # For multiplication of 2 numbers
1616
return x*y
1717

18+
19+
def calculate_average(*args, **kwargs):
20+
total_sum = sum(args)
21+
count = len(args) + len(kwargs.values())
22+
23+
for value in kwargs.values():
24+
total_sum += value
25+
26+
average = total_sum / count
27+
return average
28+
1829
def div(x:'float', y:'float')->'float': # For division of 2 numbers
1930
return x/y
2031

2132
def mod(x:'float', y:'float')->'float': # For finding the modulus of 2 numbers
2233
return x%y
2334

35+
def calculate_percentage(part, whole):
36+
37+
if whole == 0:
38+
return 0 # Avoid division by zero
39+
return (part / whole) * 100
40+
41+
2442
def factorial(n:'int')->'int': # To find the factorial of 2 numbers
2543
# single line to find factorial
2644
return 1 if (n == 1 or n == 0) else n * factorial(n - 1)

0 commit comments

Comments
 (0)