class Stack: def __init__(self): self.items=[] def isEmpty(self): return self.items==[] def push(self,item): self.items.append(item) def pop(self): return self.items.pop() def peek(self): return self.items[len(self.items)-1] def size(self): return len(self.items) s=Stack() line=input("Enter a string:") print(line[::-1]) s.push(line) print(s.pop())
I want this code to reverse the string:
Enter a string:how are you?
uoy era woh
How come its poping it out in order:
woh era uoy??
I figured it out, need to assign a new variable