Palindrome Checker Assistance

Question:

I need help with my Palindrome Checker using the provided instructions 🙁

If someone could show and explain the missing code, it would be a big help!

Palindrome Checker

Asked By: Silly Piggy

||

Answers:

Let’s say you have a list:
list1 = [1,2,3,4,5,6]

You can use
list1.append(7)
to output
[1, 2, 3, 4, 5, 6, 7]

And you can use
list1.insert(0, 0)
to output
[0, 1, 2, 3, 4, 5, 6]

Feel free to cleanup this code:

def is_palindrome(input_string):
    '''Take a string as input and return True if it is a palindrome 
       and False otherwise.'''

    # We'll create two lists to hold the string in forward 
    # and backward order to compare them later.
    forward = []
    backward = []

    # Traverse through each letter of the input string
    for letter in input_string:
        if letter != ' ':
            forward.append(letter)
            backward.insert(0, letter)

    print(forward.__str__())
    print(backward.__str__())

    str1 = ''.join(str(e) for e in forward)
    str2 = ''.join(str(e) for e in backward)
    print(str1)
    print(str2)
    if str1 == str2:
        return True
    return False
# Add any non-blank letters to the
# end of one list and to the front
# of the other list.
# Add your loop code block below this line.


# Compare the strings and return True
# or False accordingly.
# Hint: there are several ways to achieve this.
# Think about how to go from a list to a string.
# Be sure to ignore differences in upper and lower case.
# Add you code below this line.


def main():
    # Prompt user for a string to check

    print("Welcome to the Palindrome Checker Program!")
    input_str = input("Enter a string to check: ")

    # Invoke the is_palindrome function and print the result based on the return value
    # Add code below this line.
    if is_palindrome(input_str):
        print("Is Palindrome")
    else:
        print("Is not palindrome")



main()

Answered By: Yash Gupta
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.