This is a calculator I developed depending on a guideline of VidMob Engineering Take Home Exercise.
- Python 3.x should be installed
-
Store all files in calculator.zip at the same location
-
Run calculator.py
-
Working successfully, you can see the below
Please enter a mathematical expression. Type 'exit' to leave.
-
Input an expression; input 'exit' to end the program
-
Get a calculated value; an error might happen through an input validation
- (clear) Take text or string as input
- (clear) Support positive, negative, and decimal numbers
- (clear) Support +, -, *, and / operations
- (clear) Support parentheses
- (clear) A bit of documentation or help text for how to use this program
-
Infix -> Postfix
Infix Expression: A + B * C + D
Postfix Expression: A B C * + D +
Ways to do
-
Prioritize operators
-
Suppose parenthesis exists according to the priority of operators
-
Move operatros back after ")"
-
Remove parenthesis
e.g. A + B * C -> (A + ( B * C ) -> A B C * +
-
> 1 + 2
3.0
> 4*5/2
10.0
> -5+-8--11*2
9.0
> -.32 /.5
-0.64
> (4-2)*3.5
7.0
> 2+-+-4
Syntax Error
> 19 + cinnamon
Invalid Input
- Unittest will be implented
- Handle various errors
- Demo will be added
- "Stack" class will be added and replaced existed stacks
- Variable names are edited to be intuitive and readable