class Stack:
def __init__(self):
self.list = list()
def push(self, data):
self.list.append(data)
def pop(self):
return self.list.pop()
class Calculator:
def __init__(self):
self.stack = Stack()
def calculate(self, string):
list = []
for x in list:
if x == '+':
a = Stack.pop()
b = Stack.pop()
Stack.push(a + b)
elif x == '-':
a = Stack.pop()
b = Stack.pop()
Stack.push(a - b)
elif x == '*':
a = Stack.pop()
b = Stack.pop()
Stack.push(a * b)
elif x == '/':
a = Stack.pop()
b = Stack.pop()
Stack.push(a / b)
else:
Stack.push()
return Stack
calc = Calculator()
print(calc.calculate('4 6 * 2 / 2 +'))
print(calc.calculate('2 5 + 3 * 6 - 5 *'))
위 상황에서 실행하면 계산한 값이 나오는게 아니라
class '__main__.Stack'
라고 출력이 됩니다.
값을 출력하기 위해서는 어느 부분을 수정해야 할까요