Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The function main continually asks the user for a string, and calls isPalindrome to check whether each string is a palindrome. A palindrome is a

The function main continually asks the user for a string, and calls isPalindrome to check whether each string is a palindrome.

A palindrome is a word or sequence that reads the same backward as forward, e.g., noon, madam or nurses run.

The function must ignore spaces: when the user enters 'nurses run', the function returns True, to indicate that it is a palindrome.

In the code (in isPalindrome) , stack must be used to determine whether the input strings are palindromes. The program imports the Stack class

Do not make any changes to main() or to stack.py.

stack.py

""" File: stack.py

Stack class: Simple implementation of a stack using lists. """

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)

File do modify (except for main)

""" File: a5.py

"""

from stack import Stack

def isPalindrome(sentence): """Returns True if sentence is a palindrome or False otherwise.""" stk = Stack() # Creates a stack called stk.

# *** Write your code here *** return True

# *** Do not modify main() *** def main(): while True: sentence = input("Enter some text or just hit Enter to quit: ") if sentence == "": break elif isPalindrome(sentence): print("It's a palindrome.") else: print("It's not a palindrome.")

main()

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Visual Basic 4 Ole Database And Controls Superbible

Authors: Michael Hatmaker, C. Woody Butler, Ibrahim Malluf, Bill Potter

1st Edition

1571690077, 978-1571690074

More Books

Students also viewed these Databases questions