2022-06-28 21:55:53 +00:00
|
|
|
|
|
|
|
class Calculator():
|
2022-06-28 22:03:50 +00:00
|
|
|
from math import log
|
|
|
|
|
2022-06-28 21:55:53 +00:00
|
|
|
def __init__(self):
|
|
|
|
self.total = 0.0
|
|
|
|
self.actions = []
|
|
|
|
|
|
|
|
def add(self, val1, val2=None):
|
|
|
|
running_total = self.total
|
|
|
|
|
|
|
|
if val2:
|
|
|
|
total = val1 + val2
|
|
|
|
print(total)
|
|
|
|
self.actions.append(f"{val1} + {val2}")
|
|
|
|
else:
|
|
|
|
total = val1
|
|
|
|
self.actions.append(f"{val1} + {running_total}")
|
|
|
|
|
|
|
|
self.total += total
|
|
|
|
self.actions.append(f" = {self.total}")
|
|
|
|
|
|
|
|
def sub(self, val1, val2=None):
|
|
|
|
running_total = self.total
|
|
|
|
|
|
|
|
if val2:
|
|
|
|
total = val1 - val2
|
|
|
|
print(total)
|
|
|
|
self.actions.append(f"{val1} - {val2}")
|
|
|
|
else:
|
|
|
|
total = val1
|
|
|
|
self.actions.append(f"{val1} - {running_total}")
|
|
|
|
|
|
|
|
self.total -= total
|
|
|
|
self.actions.append(f" = {self.total}")
|
|
|
|
|
|
|
|
def mult(self, val1, val2=None):
|
|
|
|
running_total = self.total
|
|
|
|
|
|
|
|
if val2:
|
|
|
|
total = val1 * val2
|
|
|
|
print(total)
|
|
|
|
self.actions.append(f"{val1} * {val2}")
|
|
|
|
else:
|
|
|
|
total = val1
|
|
|
|
self.actions.append(f"{val1} * {running_total}")
|
|
|
|
|
|
|
|
self.total *= total
|
|
|
|
self.actions.append(f" = {self.total}")
|
|
|
|
|
|
|
|
def div(self, val1, val2=None):
|
|
|
|
running_total = self.total
|
|
|
|
|
|
|
|
if val2:
|
|
|
|
total = val1 / val2
|
|
|
|
print(total)
|
|
|
|
self.actions.append(f"{val1} / {val2}")
|
|
|
|
else:
|
|
|
|
total = val1
|
|
|
|
self.actions.append(f"{val1} / {running_total}")
|
|
|
|
|
|
|
|
self.total /= total
|
|
|
|
self.actions.append(f" = {self.total}")
|
|
|
|
|
|
|
|
def pow(self, val1, val2=None):
|
|
|
|
running_total = self.total
|
|
|
|
|
|
|
|
if val2:
|
|
|
|
total = val1 ** val2
|
|
|
|
print(total)
|
|
|
|
self.actions.append(f"{val1} ** {val2}")
|
|
|
|
else:
|
|
|
|
total = val1
|
|
|
|
self.actions.append(f"{val1} ** {running_total}")
|
|
|
|
|
|
|
|
self.total = total ** self.total
|
|
|
|
self.actions.append(f" = {self.total}")
|
|
|
|
|
|
|
|
def log(self, val):
|
|
|
|
print(log(val))
|
|
|
|
self.actions.append(f"log({val})")
|
|
|
|
|
|
|
|
# self.total = log(val) ** self.total
|
|
|
|
# self.actions.append(f" = {self.total}")
|
|
|
|
|
|
|
|
def showcalc(self):
|
|
|
|
for action in self.actions:
|
|
|
|
print(action)
|
|
|
|
|
|
|
|
def total(self):
|
|
|
|
return(self.total)
|
|
|
|
|
|
|
|
def ac(self):
|
|
|
|
self.total = 0.0
|
|
|
|
self.actions = []
|
|
|
|
|
|
|
|
|