Skip to content
This repository was archived by the owner on Apr 24, 2025. It is now read-only.

Commit d12b5d2

Browse files
Merge pull request #355 from Ashani-Sansala/main
Added Docstrings to functions and libraries.
2 parents e2046e0 + d1651b2 commit d12b5d2

1 file changed

Lines changed: 23 additions & 6 deletions

File tree

projects/Calculator/main.py

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,42 @@
1+
"""imports the os and time modules from the Python Standard Library.
2+
The os module provides a way of using operating system dependent functionality,
3+
like reading or writing to the file system.
4+
The time module provides various time-related functions, like getting the current
5+
time or pausing the execution of the script."""
6+
17
import os
28
import time
39

410

511
def addition():
12+
"""This function asks the user to enter a series of numbers separated by spaces.
13+
It then adds all the numbers together and returns the result."""
614
nums = list(map(int, input("Enter all numbers seperated by space: ").split()))
715
return sum(nums)
816

917

1018
def subtraction():
11-
n1 = float(input("Enter first number: "))
12-
n2 = float(input("Enter second number: "))
19+
"""This function asks the user to enter two numbers.
20+
It then subtracts the second number from the first and returns the result."""
21+
n_1 = float(input("Enter first number: "))
22+
n_2 = float(input("Enter second number: "))
1323

14-
return n1 - n2
24+
return n_1 - n_2
1525

1626

1727
def multiplication():
28+
"""Function asks user to enter a series of numbers separated by spaces.
29+
Then multiply all the numbers together and returns the result."""
30+
1831
nums = list(map(int, input("Enter all numbers seperated by space: ").split()))
19-
res = 1
32+
result = 1
2033
for num in nums:
21-
res *= num
22-
return res
34+
result *= num
35+
return result
2336

2437

2538
def division():
39+
"""Function divide two numbers"""
2640
n1 = float(input("Enter first number: "))
2741
n2 = float(input("Enter second number: "))
2842
if n2 == 0:
@@ -34,6 +48,9 @@ def division():
3448

3549

3650
def average():
51+
"""This function takes space seperated number series and then convert it to a list.
52+
Then calculates the average of that list of numbers."""
53+
3754
nums = list(map(int, input("Enter all numbers seperated by space: ").split()))
3855
return sum(nums) / len(nums)
3956

0 commit comments

Comments
 (0)