#!/usr/bin/env python
"""
Palindrome Checker
================
A palindrome is a string that reads the same backward as forward. This script checks if a given string is a palindrome.
Functions
---------
### is_palindrome(str)
Returns True if the string is a palindrome, False otherwise.
### test_palindrome(str)
Tests if the string is a palindrome and prints a message indicating whether it is or not.
### main()
The main function that calls the is_palindrome() function and tests if the input string is a palindrome.
Usage
-----
1. Run the script with the following command: `python palindrome_checker.py <string>`
2. The script will print a message indicating whether the input string is a palindrome or not.
Examples
--------
### Success
* `python palindrome_checker.py racecar`
* `python palindrome_checker.py level`
* `python palindrome_checker.py deed`
### Failure
* `python palindrome_checker.py apple`
* `python palindrome_checker.py hello`
Tests
-----
1. Test that the is_palindrome() function returns True for a palindrome string.
2. Test that the is_palindrome() function returns False for a non-palindrome string.
3. Test that the test_palindrome() function prints a message indicating whether the input string is a palindrome or not.
Implementation
--------------
import sys
def is_palindrome(str):
"""
Returns True if the string is a palindrome, False otherwise.
:param str: The string to check if it's a palindrome.
:type str: str
:return: True if the string is a palindrome, False otherwise.
:rtype: bool
"""
return str == str[::-1]
def test_palindrome(str):
"""
Tests if the string is a palindrome and prints a message indicating whether it is or not.
:param str: The string to check if it's a palindrome.
:type str: str
"""
if is_palindrome(str):
print(f"{str} is a palindrome.")
else:
print(f"{str} is not a palindrome.")
def main():
"""
The main function that calls the is_palindrome() function and tests if the input string is a palindrome.
"""
str = sys.argv[1]
test_palindrome(str)
if __name__ == "__main__":
main()
This script defines a function is_palindrome() that takes a string as input and returns True if the string is a palindrome, and False otherwise. It also defines a function test_palindrome() that takes a string as input, checks if it's a palindrome using the is_palindrome() function, and prints a message indicating whether it is or not.
The script also includes a main() function that calls the test_palindrome() function with the input string passed as an argument.
The script uses the sys.argv list to get the input string passed as an argument when the script is run.
To test the script, you can run it with a palindrome string as an argument, for example:
code
python palindrome_checker.py racecar
This should print:
code
racecar is a palindrome.
You can also run it with a non-palindrome string, for example:
code
python palindrome_checker.py apple
This should print:
code
apple is not a palindrome.
The script includes documentation for the functions and a if __name__ == "__main__": block to ensure that the script can be run directly from the command line.