From f225a945ad3d40292daaed15818713faa5afb7a2 Mon Sep 17 00:00:00 2001 From: SangayThinley <20095373@tafe.wa.edu.au> Date: Sat, 2 Dec 2023 01:58:26 +0800 Subject: [PATCH] doc(Calculator):docstring update --- .idea/inspectionProfiles/Project_Default.xml | 12 ++++ .../inspectionProfiles/profiles_settings.xml | 6 ++ .idea/misc.xml | 4 ++ .idea/python-beginner-projects.iml | 7 +++ .idea/vcs.xml | 6 ++ .idea/workspace.xml | 61 +++++++++++++++++++ diff644.diff | 0 projects/Calculator/main.py | 61 ++++++++++++++++++- 8 files changed, 156 insertions(+), 1 deletion(-) create mode 100644 .idea/inspectionProfiles/Project_Default.xml create mode 100644 .idea/inspectionProfiles/profiles_settings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/python-beginner-projects.iml create mode 100644 .idea/vcs.xml create mode 100644 .idea/workspace.xml create mode 100644 diff644.diff diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 000000000..06bb0314d --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,12 @@ + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 000000000..105ce2da2 --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 000000000..a971a2c93 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/python-beginner-projects.iml b/.idea/python-beginner-projects.iml new file mode 100644 index 000000000..ec63674cd --- /dev/null +++ b/.idea/python-beginner-projects.iml @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 000000000..35eb1ddfb --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 000000000..0d33b2e85 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,61 @@ + + + + + + + + + + + + + + + + + + { + "keyToString": { + "ASKED_ADD_EXTERNAL_FILES": "true", + "RunOnceActivity.OpenProjectViewOnStart": "true", + "RunOnceActivity.ShowReadmeOnStart": "true", + "last_opened_file_path": "C:/Users/sdthi/source/repos/python-beginner-projects" + } +} + + + + + 1697544427942 + + + + + + + + file://$PROJECT_DIR$/projects/BMI_calculator/BMI calculator.py + 11 + + + + + \ No newline at end of file diff --git a/diff644.diff b/diff644.diff new file mode 100644 index 000000000..e69de29bb diff --git a/projects/Calculator/main.py b/projects/Calculator/main.py index d6f726fdd..d3d87f878 100644 --- a/projects/Calculator/main.py +++ b/projects/Calculator/main.py @@ -3,11 +3,22 @@ def addition(): - nums = list(map(int, input("Enter all numbers seperated by space: ").split())) + """ + Sums up the two numbers entered by the user. + Returns: + int: Sum of entered numbers + """ + + nums = list(map(int, input("Enter all numbers separated by space: ").split())) return sum(nums) def subtraction(): + """ + Subtracts the two numbers entered by the user. + Returns: + int: Difference between two numbers + """ n1 = float(input("Enter first number: ")) n2 = float(input("Enter second number: ")) @@ -15,6 +26,11 @@ def subtraction(): def multiplication(): + """ + Multiplies two numbers entered by the user. + Returns: + int: Product of entered numbers + """ nums = list(map(int, input("Enter all numbers seperated by space: ").split())) res = 1 for num in nums: @@ -23,6 +39,11 @@ def multiplication(): def division(): + """ + Divides the two numbers entered by the user. + Returns: + int: Quotient of entered numbers + """ n1 = float(input("Enter first number: ")) n2 = float(input("Enter second number: ")) if n2 == 0: @@ -34,18 +55,47 @@ def division(): def average(): + """ + Calculates the average of numbers entered. + + Returns: + float:The average of the numbers entered. + """ + nums = list(map(int, input("Enter all numbers seperated by space: ").split())) return sum(nums) / len(nums) def factorial(num): + """ + Gives the factorial of a non-negative number. + + Factorial is the product of all the integers up to the number entered. + + Parameters: + num (int): A non-negative integer. + + Returns: + int: The factorial of the input number. + """ answer = 1 for i in range(num): answer *= i + 1 return answer +7 + + def complexarithmetic(): + """ + Performs complex arithmetic operations. + + Asks the user to choose from complex operations and performs the selected operation. + + Returns: + str: String representation of the complex arithmetic operation. + """ print("Enter '1' for complex addition") print("Enter '2' for complex substraction") print("Enter '3' for complex multiplication") @@ -101,6 +151,15 @@ def complexarithmetic(): def binomail(num): + """ + Calculates the binomial coefficient using the factorial function. + + Parameters: + num (list): List containing two integers where the first number entered should be greater than the second number. + + Returns: + int: Binomial coefficient. + """ result = factorial(num[0]) / (factorial(num[1]) * factorial(num[0] - num[1])) return result