发布网友 发布时间:2022-04-23 15:48
共1个回答
热心网友 时间:2022-04-06 11:24
#!/usr/bin/python
#Filename: user_input_1.py
#Function: to check whether the string is palindrome or not. Ignore space(空格), case(大小写) and punctuation(标点符号).
#Test string: "Rise to vote,sir."
import string
def reverse(text):
return text[::-1]
def is_palindrome(text):
text = text.lower()
text = text.replace(' ', '')
for char in string.punctuation:
text = text.replace(char, '')
return text == reverse(text)
def main():
something = input('Enter text:')
if (is_palindrome(something)):
print('Yes, "{0}" is a palindrome.'.format(something))
else:
print('No, "{0}" is not a palindrome.'.format(something))
if __name__ == '__main__':
main()
else:
print('user_input_1.py was imported!')