Palindrome String

Problem Statement

You have to check if given string is a Palindrome or not.

A Palindrome string is a sequence of characters that reads the same forwards and backwards.

Some of the examples for Palindrome strings are:

"radar"
"level"
"madam"
"deed"
"refer"

Input

The first line of input is a string: s.

Output

Print Palindrome if the given string is a Palindrome string, or Not Palindrome if the given string is not a Palindrome string.

As is

The boilerplate code is already there to read the inputs from user, in the main() function, and to print the message to output based on the boolean value returned by isPalindrome() function. Do not edit this code.

To do ✍

isPalindrome() has one parameter: s. Write code inside the function body to check if the given string s is a Palindrome string or not, and return a boolean value of True if the string is a Palindrome, or False otherwise.

Note: Ignore case, while comparing the strings.

Example 1

Test input

madam

Test output

Palindrome

Explanation

The given string reads the same forwards and backwards.

Example 2

Test input

helloworld

Test output

Not Palindrome

Explanation

The reverse of string 'helloworld' is 'dlrowolleh', and these not not equal. Therefore, given string is not a Palindrome.

Useful References

Python Program

# Complete the following function
# Return boolean value:
#   True  : if given string is a Palindrome
#   False : if given string is not a Palindrome
def isPalindrome(s):





# Boilerplate code - Do not edit the following
def main():
    s = input()
    if isPalindrome(s):
        print("Palindrome")
    else:
        print("Not Palindrome")

if __name__ == "__main__":
    main()

Input and Outputs 1

kayak
Palindrome

Input and Outputs 2

hello world
Not Palindrome

Input and Outputs 3

nooner
Not Palindrome

Input and Outputs 4

racecar
Palindrome
# Complete the following function
def isPalindrome(s):
    s = s.lower()
    if s == s[::-1]:
        return True
    return False

# Boilerplate code - Do not edit the following
def main():
    s = input()
    if isPalindrome(s):
        print("Palindrome")
    else:
        print("Not Palindrome")

if __name__ == "__main__":
    main()
show answer
main.py
⏵︎ Run Tests
Reset
Download
×
Code copied to clipboard successfully 👍