palindrome

2024. 11. 28. 15:38정보처리,전산/Python

반응형

 

def ispal(s):
    s = s.lower().replace(" ", "")  # Remove spaces and convert to lowercase
    return s == s[::-1]  # Check if the string is a palindrome

s = "A man a plan a canal Panama"  # Updated input data
print(ispal(s))  # Output the palindrome check result

 

Output:

True

The result is True because "A man a plan a canal Panama" is a palindrome when spaces and case are ignored.

반응형