38.5k views
5 votes
Write a function check_palindrome that takes a string as an input and within that function determines whether the input string is a palindrome or not (a word or phrase that is read the same forward as it is backward - i.e. kayak, dad, etc.). If it is a palindrome, return 'Hey! That's a palindrome!' If it is not a palindrome, return 'Bummer. Not a palindrome.' Remember that you created a function that can reverse a string above.

1 Answer

4 votes

Answer:

The function in Python is as follows:

def check_palindrome(strn):

retstr = "Bummer. Not a palindrome."

if strn[len(strn)::-1] ==strn:

retstr = "Hey! That's a palindrome!"

return retstr

Step-by-step explanation:

This defines the function

def check_palindrome(strn):

This sets the return string to not a palindrome

retstr = "Bummer. Not a palindrome."

This checks if the original string and the reversed string are the same

if strn[len(strn)::-1] ==strn:

If yes, the return string is set to palindrome

retstr = "Hey! That's a palindrome!"

This returns the expected string

return retstr

The function to reverse the string is not given; and the programming language. So, I solve the question without considering any function

User Dzejms
by
4.6k points