would this then mean that i take poped element then try to add to with a symbol who is for example + and add it with the other poped element and get result ? and where exactly should i write this command ?
meanwhile i was trying to upgrade my own:
meanwhile i was trying to upgrade my own:
class stack(): def __init__(self): self.items = [] def push(self, item): self.items.append(item) def pop(self): return self.items.pop() def get_stack(self): return self.items def is_empty(self): return self.items == [] def is_full(self): return self.items == [1] def size(self): return len(self.items) def eval(self): s = stack() for symbol in self: if symbol in "0123456789": s.append(int(symbol)) plus = None elif not s.is_empty(): if symbol == "+": plus = s.push() + s.push() elif symbol == "-": plus = s.push() - s.push() elif symbol == "*": plus = s.push() * s.push() elif symbol == "/": plus = s.push() / s.push() if plus is not None: s.append(plus) else: raise Exception("unknown value %s" % symbol) return s.pop() s = stack() print("Is stack empty?") print(s.is_empty()) print("Is stack Full?") print(s.is_full()) s.push(9) s.push('+') s.push(5) s.push('+') s.push(8) s.push('+') s.push(7) s.push('+') s.push(3) print(s.size()) print(s.get_stack()) print(s.eval()) s.pop() s.pop() print(s.get_stack())but ran into a problem where it does not recognize this comand and i can seem to figure out why:
Error:
elif not s.is_empty():
^
SyntaxError: invalid syntax