Skip to content

Commit

Permalink
Update calculator.py
Browse files Browse the repository at this point in the history
  • Loading branch information
ikostan committed Dec 3, 2024
1 parent 140c1d8 commit eee8fd6
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions kyu_3/calculator/calculator.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""
Solution for -> Calculator
Solution for -> Calculator.
Create a simple calculator that given a string
of operators '()', '+', '-', '*', '/' and numbers separated
by spaces returns the value of that expression.
Expand All @@ -10,6 +11,8 @@

class Calculator:
"""
Calculator class.
Given string of operators '()', '+', '-', '*', '/'
and numbers separated by spaces.
Returns the value of that expression.
Expand All @@ -22,6 +25,8 @@ def __init__(self):
@property
def result(self) -> float:
"""
Get result.
1. Set result value by converting
string value to a float
2. Return result value
Expand All @@ -34,6 +39,8 @@ def result(self) -> float:
@staticmethod
def __calculate(i: int, char: str, strings: list):
"""
Calculate method.
1. Perform math operation
2. Reorganize math expression
Expand Down Expand Up @@ -63,7 +70,10 @@ def __calculate(i: int, char: str, strings: list):

def __process_math_expression(self, string: str, operators: list) -> str:
"""
Perform all operation with multiplications, divisions, additions and subtractions
Process math calculation.
Perform all operation with multiplications, divisions,
additions and subtractions.
:param string: str, input string
:param operators: list, contains math operators
:return: str, output string with no ‘*’, ‘/’, ‘+’, ‘-‘
Expand All @@ -80,7 +90,9 @@ def __process_math_expression(self, string: str, operators: list) -> str:

def evaluate(self, string: str) -> float:
"""
Returns value of the given expression
Evaluate method.
Returns value of the given expression.
:param string: str, input string to evaluate
:return: (float) result
"""
Expand Down

0 comments on commit eee8fd6

Please sign in to comment.