Skip to content

Commit

Permalink
feat: implement cos and sin
Browse files Browse the repository at this point in the history
  • Loading branch information
gciatto committed May 7, 2024
1 parent 28d0303 commit c7e11cb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
8 changes: 7 additions & 1 deletion calculator/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,16 @@ def power(self):

def logarithm(self):
self._append("log")

def cos(self):
self._append("cos")

def sin(self):
self._append("sin")

def compute_result(self) -> Number:
try:
from math import sqrt
from math import sqrt, cos, sin
result = eval(self.expression)
if isinstance(result, Number):
self.expression = str(result)
Expand Down
6 changes: 5 additions & 1 deletion calculator/ui/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
['1', '2', '3', '-'],
['.', '0', '=', '+'],
['(', '√', '^', ')'],
['log'],
['log', 'cos', 'sin'],
]


Expand Down Expand Up @@ -81,6 +81,10 @@ def on_button_press(self, button):
case "log":
self._calc.logarithm()
self._calc.open_parenthesis()
case "cos":
self._calc.cos()
case "sin":
self._calc.sin()
case _:
self._calc.digit(button.text)
self.display.text = self._calc.expression or "0"
Expand Down

0 comments on commit c7e11cb

Please sign in to comment.