https://github.com/cau777/smart-calculator
A simple calculator in Python that supports basic operations, variable and parenthesis.
https://github.com/cau777/smart-calculator
calculator postfix postfix-notation python stack
Last synced: 2 days ago
JSON representation
A simple calculator in Python that supports basic operations, variable and parenthesis.
- Host: GitHub
- URL: https://github.com/cau777/smart-calculator
- Owner: cau777
- License: mit
- Created: 2021-05-14T19:21:32.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2021-05-14T22:01:09.000Z (about 5 years ago)
- Last Synced: 2025-03-24T17:21:20.821Z (over 1 year ago)
- Topics: calculator, postfix, postfix-notation, python, stack
- Language: Python
- Homepage:
- Size: 4.88 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Smart-Calculator
A simple calculator in Python that supports basic operations, variable and parenthesis. It uses postfix notation, stacks and dictionaries.
I made this project for JetBrains Academy
# How to convert infix to postfix
* Add operands (numbers and variables) to the result (postfix notation) as they arrive.
* If the stack is empty or contains a left parenthesis on top, push the incoming operator on the stack.
* If the incoming operator has higher precedence than the top of the stack, push it on the stack.
* If the precedence of the incoming operator is lower than or equal to that of the top of the stack, pop the stack and add operators to the result until you see an operator that has smaller precedence or a left parenthesis on the top of the stack; then add the incoming operator to the stack.
* If the incoming element is a left parenthesis, push it on the stack.
* If the incoming element is a right parenthesis, pop the stack and add operators to the result until you see a left parenthesis. Discard the pair of parentheses.
* At the end of the expression, pop the stack and add all operators to the result.