The standard String Calculator kata is much simpler that this one. The task is to parse the string, find all numbers and calculate the sum. There is also the RPN calculator kata, which is closer to it.
This one is the calculator, which is parsing the input (string) as infix notated operation and return its result. In short: you can type the mathematical operation in human way and see the result.
- adding, subtraction
- multiple, division
- negation (minus before some expression)
- power
- brackets (the round one only)
- float numbers, in simple and scientific notation
- simple validation (double operators, letters in place of numbers etc.)
The module is ready to use:
from calculator import calculate
print(calculate('32 + 45 * 34 - 23'))