python [已关闭]

xxhby3vn  于 2023-03-28  发布在  Python
关注(0)|答案(1)|浏览(78)

已关闭。此问题需要details or clarity。当前不接受答案。
**想要改进此问题?**添加详细信息并通过editing this post阐明问题。

昨天关门了。
Improve this question
我需要帮助我的回文检查器使用提供的说明:(
如果有人能展示并解释丢失的代码,那将是一个很大的帮助!
Palindrome Checker

pqwbnv8z

pqwbnv8z1#

假设你有一个列表:list1 = [1,2,3,4,5,6]
可以使用list1.append(7)输出[1, 2, 3, 4, 5, 6, 7]
可以使用list1.insert(0, 0)输出[0, 1, 2, 3, 4, 5, 6]
请随意清理此代码:

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()

相关问题