Skip to content

Palindrome Checking

Palindrome Checking

Project Goals

This engineering effort invites you to implement a program called palindromechecker that can determine whether or not an input word is or is not a palindrome, or a word that is spelled the same both forwards and backwards. For instance, the word civic is a palindrome because it is spelled the same both forwards and backwards while example is not. Specifically, you will implement one approach to palindrome checking that uses recursion and another that reverses the word. In addition to implementing these two approaches for palindrome checking, you will create a comprehensive command-line interface using Typer. Along with implementing your own test cases for the functions that determine whether the word is a palindrome, you will also add documentation to your palindromechecker in the form of docstrings for both the functions and the module.

Project Access

If you are a student enrolled in a Computer Science class at Allegheny College, you can access this assignment by clicking the link provided to you in Discord. Once you click this link it will create a GitHub repository that you can clone to your computer by following the general-purpose instructions in the description of the technical skills. Specifically, you will need to use the git clone command to download the project from GitHub to your computer. Now you are ready to add source code and documentation to the project!

Note

If you are an emerging proactive programmer who is not enrolled in a Computer Science class at Allegheny College, you can still work on this assignment! To get started, you should click the "Use this template" button in the palindrome-checker-starter GitHub repository and create your own version of this project's source code. After creating your GitHub repository, you can follow all of the other steps!

Expected Output

This project invites you to implement a Python program, called palindromechecker, that features different ways determine whether or not a number is a palindrome. After you finish a correct implementation of all the program's features, running it with the command poetry run palindromechecker --word civic --approach recursive, it will produce this output. See a later section for more output examples!

โœจ Awesome, using the recursive approach for palindrome checking!

๐Ÿ”– Going to check to see if the word "civic" is a palindrome!

๐Ÿ˜† Is this word a palindrome? Yes, it is!

Don't forget that you can display palindromechecker's help menu and learn more about its features by typing poetry run palindromechecker --help to show the following output. This help menu shows that palindromechecker has a --approach flag that enables it to check whether or not a word is a palindrome through the use of a reverse-based or recursive-based technique.

โ•ญโ”€ Options โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚ *  --word                    TEXT                [default: None]      โ”‚
โ”‚                                                  [required]           โ”‚
โ”‚    --approach                [recursive|reverse  [default: reverse]   โ”‚
โ”‚                              ]                                        โ”‚
โ”‚    --install-completโ€ฆ        [bash|zsh|fish|pow  Install completion   โ”‚
โ”‚                              ershell|pwsh]       for the specified    โ”‚
โ”‚                                                  shell.               โ”‚
โ”‚                                                  [default: None]      โ”‚
โ”‚    --show-completion         [bash|zsh|fish|pow  Show completion for  โ”‚
โ”‚                              ershell|pwsh]       the specified shell, โ”‚
โ”‚                                                  to copy it or        โ”‚
โ”‚                                                  customize the        โ”‚
โ”‚                                                  installation.        โ”‚
โ”‚                                                  [default: None]      โ”‚
โ”‚    --help                                        Show this message    โ”‚
โ”‚                                                  and exit.            โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

Please note that the provided source code does not contain all of the functionality needed to produce the output displayed in this section and later in the project description. As the next section explains, you should add the features needed to ensure that palindromechecker produces the expected output! Importantly, this project invites you to add both a recursion-based and reversal-based algorithm for palindrome checking.

Note

Don't forget that if you want to run the palindromechecker program you must use your terminal window to first go into the GitHub repository containing this project and then go into the palindromechecker directory that contains the project's source code. Finally, remember that before running the program you must run poetry install to add its dependencies, such as Pyinstrument, Pytest, and Rich.

Adding Functionality

If you study the file palindromechecker/palindromechecker/main.py you will see that it has many TODO markers that designate the parts of the program that you need to implement before palindromechecker will produce correct output. Once you complete a task associated with a TODO marker, make sure that you delete it and revise the prompt associated with the marker into a meaningful comment. To ensure that the program works correctly, you must implement all of these functions in the palindrome module:

  • def to_chars(word: str) -> str
  • def is_palindrome(word: str) -> bool
  • def is_palindrome_recursive(word: str) -> bool
  • is_palindrome_reverse(word: str) -> bool

After finishing your implementation of palindromechecker you should repeatedly run the program in different configurations to confirm that it produces the correct output. Since the palindromechecker provides a checking mode based on reversing the string or recursively checking the string, you should make sure that both approaches work correctly. You should also confirm that the palindromechecker can correctly determine when a word both is and is not a palindrome. Here are some examples that show the program's correct execution for different values for the --word and --approach arguments. If you correctly resolve all of the TODO markers in the provided source code your program should produce the same output for each of these commands.

  • poetry run palindromechecker --word civic --approach reverse
โœจ Awesome, using the recursive approach for palindrome checking!

๐Ÿ”– Going to check to see if the word "civic" is a palindrome!

๐Ÿ˜† Is this word a palindrome? Yes, it is!
  • poetry run palindromechecker --word civic --approach reverse
โœจ Awesome, using the reverse approach for palindrome checking!

๐Ÿ”– Going to check to see if the word "civic" is a palindrome!

๐Ÿ˜† Is this word a palindrome? Yes, it is!
  • poetry run palindromechecker --word origin --approach recursive
โœจ Awesome, using the recursive approach for palindrome checking!

๐Ÿ”– Going to check to see if the word "origin" is a palindrome!

๐Ÿ˜† Is this word a palindrome? No, it is not!
  • poetry run palindromechecker --word origin --approach reverse
โœจ Awesome, using the reverse approach for palindrome checking!

๐Ÿ”– Going to check to see if the word "origin" is a palindrome!

๐Ÿ˜† Is this word a palindrome? No, it is not!

Running Checks

If you study the source code in the pyproject.toml file you will see that it includes the following section that specifies different executable tasks like lint. If you are in the listsorting directory that contains the pyproject.toml file and the poetry.lock file, the tasks in this section make it easy to run commands like poetry run task lint to automatically run all of the linters designed to check the Python source code in your program and its test suite. You can also use the command poetry run task black to confirm that your source code adheres to the industry-standard format defined by the black tool. If it does not adhere to the standard then you can run the command poetry run task fixformat and it will automatically reformat the source code.

Along with running tasks like poetry run task lint, you can leverage the relevant instructions in the technical skills to run the command gatorgrade --config config/gatorgrade.yml to check your work. If your work meets the baseline requirements and adheres to the best practices that proactive programmers adopt you will see that all the checks pass when you run gatorgrade. You can study the config/gatorgrade.yml file in your repository to learn how the GatorGrade program runs GatorGrader to automatically check your program and technical writing. If your program has all of the anticipated functionality, you can run the command poetry run task test and see that the test suite produces output like the following. Can you add comments to explain how these tests work? What are the key components of every test case created with Pytest? How do the tests "cover" the source code the of the program?

tests/test_main.py ....
tests/test_palindrome.py ....
tests/test_util.py ..

This project comes with other tasks that you can run once you have used Poetry to install all of the dependencies. For instance, if you find that your Python source code is not in adherence with the required formatting rules, you can run poetry run task fixformat to automatically return it to the correct format! You can also run commands like poetry run task mypy to check the program's use of data types and poetry run task pylint to ensure that your source code adheres to other established programming conventions. You can use these built-in tasks to understand and improve your code's quality! For this assignment, you can also use the command poetry run task coverage to create a coverage report, like the one shown below, that reveals how well your tests exercise the source code in the program palindromechecker program. You should try to write test cases that completely cover the program's source code, producing a report like this one.

Name                              Stmts   Miss  Cover   Missing
---------------------------------------------------------------
palindromechecker/__init__.py         1      0   100%
palindromechecker/main.py            26      0   100%
palindromechecker/palindrome.py      18      0   100%
palindromechecker/util.py             4      0   100%
---------------------------------------------------------------
TOTAL                                49      0   100%
Note

Don't forget that when you commit source code or technical writing to your GitHub repository for this project, it will trigger the run of a GitHub Actions workflow. If you are a student at Allegheny College, then running this workflow consumes build minutes for the course's organization! As such, you should only commit to your repository once you have made substantive changes to your project and you are ready to confirm its correctness. Before you commit to your GitHub repository, you can still run checks on your own computer by using Poetry and GatorGrader.

Project Reflection

Once you have finished both of the previous technical tasks, you can use a text editor to answer all of the questions in the writing/reflection.md file. For instance, you should provide the output of the Python program in a fenced code block, explain the meaning of the Python source code segments that you implemented, and answer all of the other questions about your experiences in completing this project. A specific goal of the reflection for this project is to continue to explore how test cases and test coverage information can help a developer to both establish a confidence in the correctness of and to find bugs in a Python program. Once you have finished addressing the prompts in the writing/reflection.md file that have TODO makers given as reminders, make sure that you either delete the prompt or carefully integrate a revised version of it into your writing.

Project Assessment

Since this project is an engineering effort, it is aligned with the evaluating and creating levels of Bloom's taxonomy. You can learn more about how a proactive programming expert will assess your work by examining the assessment strategy. From the start to the end of this project you may make an unlimited number of reattempts at submitting source code and technical writing that meet all aspects of the project's specification.

Note

Before you finish all of the required deliverables required by this project is worth pausing to remember that the instructor will give advance feedback to any learner who requests it through GitHub and Discord at least 24 hours before the project's due date! Seriously, did you catch that? This policy means that you can have a thorough understanding of ways to improve your project before its final assessment! To learn more about this opportunity, please read the assessment strategy for this site.

Seeking Assistance

Emerging proactive programmers who have questions about this project are invited to ask them in either the GitHub discussions forum or the Proactive Programmers Discord server. Before you ask your question, please read the advice concerning how to best participate in the Proactive Programmers community. If you find a mistake in this project, please describe it and propose a solution by creating an issue in the GitHub Issue Tracker.


Updated: 2023-04-14   Created: 2021-08-12
Create an issue with feedback about "Palindrome Checking"
Check out all the exciting topics covered on this site