I've searched all over, but Have not been able to find exactly what I need help on.
I am creating a program that takes user input of a word and determines if it is a Palindrome or not....the catcher is I need to use stacks. They are confusing to me. I can write a simple Palindrome program without stacks, but not with. Any advice?
This is what I have so far.
class Stack(): def __init__(self): self._items =  def push(self,obj): self._items.append(obj) def pop(self): return self._items.pop() def peek(self): return self._items[-1] def isEmpty(self): return len(self._items)==0 def __len__(self): return len(self._items) def __str__(self): return "bottom" +str(self._items)+ "top" def reverse(self): return self._items.reverse()
and then this is where i am really confused.
from stack import Stack stack = Stack() stack2 = Stack() def checkPalindrome(phrase): word = raw_input("Enter a word or number sequence to check for palidrom: ") for ch in phrase: if 'A' <=ch,='Z' or 'a' <=ch<='z' or '16'<=ch<='25': stack.push(ch) for letters in phrase: if 'A' <=ch,='Z' or 'a' <=ch<='z' or '16'<=ch<='25': stack2.push(letters) stack2.reverse() #I need to have some type of Yes Palindrome or No Palindrom statement after the program decides if it is or is not a palindrome. I am not sure how to do that with the stacks? return result