Palindrome

Palindrome

It reads the same forwards and backwards.

A palindrome is a word, number or phrase that reads the same backwards as forwards, such the words madam or racecar.

Make


Write a program that allows the user to enter a word or sentence. The program outputs whether the input is a palindrome or not.

Use this boilerplate code as a starting point:

Success Criteria

Remember to add a comment before a subprogram, selection or iteration statement to explain its purpose.

Complete the subprogram called `palindrome` that:

  1. Takes a string parameter `phrase` to be processed.
  2. Returns True if `phrase` is a palindrome.
  3. Returns False if `phrase` is not a palindrome.

Note the algorithm will need to ignore case, whitespace and punctuation.

Complete the `main program` so that:

  1. The user can input a word, phrase or sequence of digits.
  2. The program outputs whether the phrase is a palindrome or not.

Typical inputs and outputs from the program would be:

Enter a phrase: ABBA

ABBA is a palindrome.


Enter a phrase: 02/02/2020

02/02/2020 is a palindrome.


Enter a phrase: A man, a plan, a canal – Panama

A man, a plan, a canal – Panama is a palindrome.


Enter a phrase: Hello World

Hello World is not a palindrome.

Knowledge Organiser

Use these resources as a reference to help you meet the success criteria.

Programming guide:

Evaluate


Run the unit tests below to check that your program has met the success criteria.

Enter a phrase: saippuakivikauppias

saippuakivikauppias is a palindrome.

Enter a phrase: Tattarrattat

Tattarrattat is a palindrome.

Enter a phrase: A man, a plan, a canal – Panama

A man, a plan, a canal – Panama is a palindrome.

Enter a phrase: palindrome

palindrome is not a palindrome.

Enter a phrase: 1234321

1234321 is a palindrome.

Enter a phrase: String manipulation is fun!

String manipulation is fun! is not a palindrome.

Check that you have:

  • Used comments within the code to describe the purpose of subprograms, conditions and iterations.
  • Used meaningful identifier names. That means the names of subprograms and variables indicate what they are for.
Craig'n'Dave logo

Craig ‘n’ Dave

Bett Awards 2024 Finalist