Hi everyone im new to python and still trying to get a hang for it and ive ran into a problem when creating my basic stack program and cant figure out where to go next was hoping if anyone could guide me the right way :)
here is the code:
here of what i was thinking of but gotten stuck on
here is the code:
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) s = stack() print("ar stack tuscias?") print(s.is_empty()) print("ar stack pilnas?") 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())This program works on it self just fine the problem i have is how do i take value of "s.push(x)" and add it or multiply or w/e and get an answer in this example how do i make him 9+5+8+7+3 whitout just writing print 9+5 was hopping to get answer with define so if numbers or symbol changes it would react acording to it.
here of what i was thinking of but gotten stuck on
for symbol in self: if symbol in "0123456789": s.append(int(symbol)) if symbol == "+": plus = s.pop() + s.pop() elif symbol == "-": plus = s.pop() - s.pop() elif symbol == "*": plus = s.pop() * s.pop() elif symbol == "/": plus = s.pop() / s.pop()its one of those moments where i think im close but cant figure it out