Skip to content

The full infix calculator kata, written in Python

License

Notifications You must be signed in to change notification settings

dplocki/calculator-kata

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

60 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Calculator kata

GitHub Python 3 GitHub top language Code style: black GitHub last commit

📒 Idea

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.

✔️ Functionality

  • 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.)

⚙️ Run

The module is ready to use:

from calculator import calculate

print(calculate('32 + 45 * 34 - 23'))