kyu_3.calculator package

Submodules

kyu_3.calculator.calculator module

Create a simple calculator that given a string of operators (), +, -, *, / and numbers separated by spaces returns the value of that expression

class kyu_3.calculator.calculator.Calculator[source]

Bases: object

Given string of operators (), +, -, *, / and numbers separated by spaces. Returns the value of that expression.

__calculate(char: str, strings: list)
  1. Perform math operation

  2. Reorganize math expression

Parameters
  • i – char (math operation) index

  • char – math operation

  • strings – math expression

Returns

result

__process_math_expression(string: str, operators: list) → str

Perform all operation with: multiplications, divisions, additions and subtractions

Parameters

string – input string

Returns

output string with no ‘*’, ‘/’, ‘+’, ‘-‘

evaluate(string: str) → float[source]

Returns value of the given expression

Parameters

string – a string of operators (), +, -, *, / and numbers separated by spaces

Returns

calculated value of the given expression

kyu_3.calculator.test_calculator module

Testing Calculator class

class kyu_3.calculator.test_calculator.CalculatorTestCase(methodName='runTest')[source]

Bases: unittest.case.TestCase

Testing Calculator class

test_calculator()[source]

Testing Calculator class

A simple calculator that given a string of operators (), +, -, *, / and numbers separated by spaces will return the value of that expression

Module contents