Advertisement
Python253

is_palindrome

Mar 3rd, 2024 (edited)
763
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.10 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # Filename: is_palindrome.py
  4. # Author: Jeoi Reqi
  5.  
  6. """
  7. Is Palindrome Script
  8.  
  9. This script checks whether a user-input string is a palindrome or not.
  10. It utilizes a function, is_palindrome, to perform the palindrome check.
  11.  
  12. Requirements:
  13. - Python 3
  14.  
  15. Usage:
  16. 1. Run the script.
  17. 2. Enter a string when prompted.
  18. 3. The script will display whether the entered string is a palindrome or not.
  19. """
  20.  
  21. def is_palindrome(string):
  22.     """Check if string is a Palindrome.
  23.  
  24.    Args:
  25.        string (str): String.
  26.  
  27.    Returns:
  28.        bool: True if string is a palindrome, False otherwise.
  29.  
  30.    """
  31.     string = string.strip()
  32.     return string == string[::-1]
  33.  
  34. def main():
  35.     # Get user input
  36.     user_input = input("Enter a string: ")
  37.  
  38.     # Check if the input is a palindrome
  39.     result = is_palindrome(user_input)
  40.  
  41.     # Display the result
  42.     if result:
  43.         print(f"The entered string '{user_input}' is a palindrome.")
  44.     else:
  45.         print(f"The entered string '{user_input}' is not a palindrome.")
  46.  
  47. if __name__ == "__main__":
  48.     main()
  49.  
  50.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement