Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring #5

Merged
merged 3 commits into from
Aug 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ Currently the program supports 'Addition :heavy_plus_sign:', 'Subtraction :heavy

#### User interface of PyCalc *v0.1-beta* :desktop_computer:

![As of v0.1-alpha](https://github.com/maddypie/PyCalc/blob/master/PyCalcDemo.png)
![As of v0.1-beta](https://github.com/maddypie/PyCalc/blob/master/PyCalcDemo.png)

#### Tasks List :writing_hand:
- [ ] **Refactor source.py**
- [x] **Refactor source.py**
- [x] Add 'Copy' functionality, to copy the result. Currently 'Copy' button does not do anything.
- [x] Bind 'Number-pad' keys to enter input.
- [ ] Option to switch between 'Simple' to 'Advanced' mode. Advanced mode should have more funtionalities.
Expand Down
278 changes: 0 additions & 278 deletions WIP refactoring source.py

This file was deleted.

36 changes: 36 additions & 0 deletions core_logic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
class Calculate():
ans: str
_get_value = {
'/': lambda x, y: x/y,
'*': lambda x, y: x*y,
'+': lambda x, y: x+y,
'-': lambda x, y: x-y
}

def __init__(self, expr_as_list, operators):
self.expr_as_list = expr_as_list
self.operators = operators

def calculate(self) -> str:
while self.operators[0] in self.expr_as_list:
index = self.expr_as_list.index(self.operators[0])
self.__partial_calculate(index)
while self.operators[1] in self.expr_as_list:
index = self.expr_as_list.index(self.operators[1])
self.__partial_calculate(index)
while self.operators[2] in self.expr_as_list:
index = self.expr_as_list.index(self.operators[2])
self.__partial_calculate(index)
while self.operators[3] in self.expr_as_list:
index = self.expr_as_list.index(self.operators[3])
self.__partial_calculate(index)
self.ans = self.expr_as_list[0]
return self.ans

def __partial_calculate(self, index) -> None:
operator = self.expr_as_list[index]
left_operand = float(self.expr_as_list[index-1])
right_operand = float(self.expr_as_list[index+1])
sub_result = self._get_value[operator](left_operand, right_operand)
self.expr_as_list[index-1:index+2] = [str(sub_result)]

Loading