64.3k views
1 vote
A palindrome is a string that is the same when read left to right as when read right to left. Write a program that determines if an arbitrary string is a palindrome. Assume that the string can have blanks, punctuation, capital letters and lower case.

1 Answer

4 votes

Answer:

In Python:

strng = input("String: ")

revstrng = strng[::-1]

if strng == revstrng:

print("True")

else:

print("False")

Step-by-step explanation:

This prompts user for string input

strng = input("String: ")

This reverses the string input by the user

revstrng = strng[::-1]

This checks if strings and the reverse string are equal

if strng == revstrng:

Prints True, if yes

print("True")

Prints False, if otherwise

else:

print("False")

User Fusspawn
by
4.9k points