Question: Activities Part 1 : Checking Palindromes A string is a palindrome if it reads the same forward and backward. The words mom, dad, and noon,

Activities

Part 1: Checking Palindromes

A string is a palindrome if it reads the same forward and backward. The words mom, dad, and noon, for instance, are all palindromes.

The problem is to write a program that prompts the user to enter a string and reports whether the string is a palindrome. One solution is to have the program check whether the first character in the string is the same as the last character. If so, then the program can check whether the second character is the same as the second-to-last character. This process continues until a mismatch is found or all the characters in the string are checked, except for the middle character if the string has an odd number of characters.

To implement this idea, you can use two variables, say low and high, to denote the position of two characters at the beginning and the end in a string s.

Write a function isPalindrome() that takes a string and return True if it is a palindrome, and False if not.

Write the main() function that takes the string from the user and passes it to the isPalindrome() function, then prints the appropriate message

Sample Run

Enter a string: noon

noon is a palindrome

Enter a string: moon

moon is not a palindrome

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!