1. Engineering
  2. Computer Science
  3. a palindrome is a number or a text phrase that...

Question: a palindrome is a number or a text phrase that...

Question details
  • A palindrome is a number or a text phrase that reads the same backwards as it does forwards. For example, each of the following seven-digit integers is a palindrome: 1234321, 5555555, 4565654 and1126211. Each of the following seven-character strings is a palindrome: abcdcba, deified,racecar, peeweep, rotator.
  • Write a program that reads in a seven-character string/number and determines whether or not it is a palindrome. It should print PALINDROME or NOT based on whether or not it is, indeed, a palindrome or not.
  • If the input is not 7 characters long, output an error message labeled with ERROR and don't attempt to process the value.
  • Write a Perl program, keeping in mind different ways to test string and numeric equality.
  • Think about how you can test different types of input, including string/character data and numeric data. For this program, you can't use the reverse function, which over-trivializes the solution.
  • We're focusing on practicing with all of the tools available in Perl, so you're being guided to make this solution a bit more complex than it could be. :)
  • Remember to have #!/usr/bin/env perl as the very first line of your program to use the appropriate version of Perl on the system (installed with perlbrew).
  • Use use Modern::Perl; in your program.
  • Output the phrases PALINDROME OR NOT exactly on a separate line from the input.
  • Do not use arrays or other libraries for this program.
  • Make sure to use the use Modern::Perl in your program.
  • You may not use the reverse function, which reduces the solution to the incredibly simple:if($originaleq reverse $original)

{

say"PALINDROME!";

}

Example

Enter in a 7 character phrase: 1111111

PALINDROME

Example

Enter in a 7 character phrase: racecar

PALINDROME

Example

Enter in a 7 character phrase: 1234321

PALINDROME

Example

Enter in a 7 character phrase: 1234522

NOT

Example

Enter in a 7 character phrase: abluent

NOT

Example

Enter in a 7 character phrase: 1234567

NOT

Example

Enter in a 7 character phrase: 123

ERROR: That is not a 7-character input.

Example

Enter in a 7 character phrase: 12345678

ERROR: That is not a 7-character input.

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution