215k views
2 votes
Special words are those words that start and end with the same letter. [14]

Examples: COMIC, WINDOW, EXISTENCE
Palindrome words are those words that read the same from left to right and vice- versa.
Examples: MADAM, LEVEL, CIVIC, MALAYALAM
Note: All palindromes are special words, but all special words are not palindromes.
Write a program to accept a word. Check and print whether the word is a Palindrome word or only a special word or neither of them.
Write 2 comment lines at least. Variable description table need not be written.

User Hany Sakr
by
4.7k points

1 Answer

4 votes

Answer:

This program is written in python programming language

The program uses few comments (See Explanation for further explanation of each line)

See attachment for proper format view of the source code

Program starts here

#Prompt user for Input

inpstring = input("Enter a string: ")

#Reverse user input

revstring = inpstring[::-1]

#Calculate length of user input

i = len(inpstring)

if(inpstring.upper() == revstring.upper()):

print("The input string is Palindrome")

else:

if(inpstring[0].upper() == inpstring[i-1].upper()):

print("The input string is a Special Word")

else:

print("The input string is neither Palindrome nor Special")

Step-by-step explanation:

inpstring = input("Enter a string: ")-> This line accepts input from user

revstring = inpstring[::-1]-> This line reverses user input

i = len(inpstring)-> This line calculates the length of user input

The following if statement checks for palindromes; i.e. if input string is equal to reversed string

if(inpstring.upper() == revstring.upper()):

print("The input string is Palindrome")

If the above is statement is not true, the following is executed (to check for special word)

else:

The following if statement checks if the first letter of the input string is equal to its last letter

if(inpstring[0].upper() == inpstring[i-1].upper()):

print("The input string is a Special Word")

If the above statement if not true, then input string is not a special word and it's not palindromic.

Hence, the its accompanying else statement will be executed

else:

print("The input string is neither Palindrome nor Special")

Special words are those words that start and end with the same letter. [14] Examples-example-1
User Sparsh Dutta
by
5.1k points