Answer to Question #298907 in Python for lemhs

Question #298907

A palindrome is a string that reads the same forwards as backwards. Using only a fixed number of stacks and queues, the stack and queue ADT functions, and a fixed number of int and char variables, write an algorithm to determine if a string is a palindrome. Assume that the string is read from standard input one character at a time. The algorithm should output true or false as appropriate.


1
Expert's answer
2022-02-17T05:21:22-0500

from cgitb import text

from os import popen

 

class Stack:

  def __init__(self):

    self.items = []

 

  def is_empty(self):

    return self.items == []

 

  def push(self, data):

    self.items.append(data)

 

  def pop(self):

    return self.items.pop()

 

 

s = Stack()

input_text = input('Please enter the string: ')

 

for character in input_text:

  s.push(character)

 

textrev = ''

while not s.is_empty():

  textrev = textrev + s.pop()

 

if input_text == textrev:

  print('True')

else:

  print('False')

 

                                                                                     

 output

input: pop

output: True


input: clear

output: False

 

 



Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

lehms
18.02.22, 11:49

Are you sure about the answer?

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS