Contents

Python Challenges

Different challenges in Python

Website Visitors:
Contents

Palindrome

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
def IsPalindrome(newstr):
    if newstr == newstr[::-1]:
        print("It is palindrome")
    else:
        print("It is not palindrome")

while True:
    userinput = input("Enter a word to test as palindrome: ")
    if userinput == "exit":
        break

    newstr = ""
    # Change the whole user input to lower case. You can also change it to upper case.
    xx = userinput.lower()

    # For each letter check if it alphabet or a number. Spaces does not fall under alphabets or numbers. So they will be ignored.
    for x in xx:
        if x.isalnum():
            newstr += x

    IsPalindrome(newstr)

Your inbox needs more DevOps articles.

Subscribe to get our latest content by email.