Add simple is_even algorithm#14061
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds a new is_even algorithm to the maths directory that determines whether an integer is even using the modulo operator.
- Introduces a simple
is_even()function with type hints - Uses the modulo operator (
n % 2 == 0) to check for evenness - Includes basic documentation describing the function's purpose
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| def is_even(n: int) -> bool: | ||
| """ | ||
| Check whether a number is even. | ||
|
|
||
| :param n: Integer number | ||
| :return: True if even, False otherwise | ||
| """ | ||
| return n % 2 == 0 |
There was a problem hiding this comment.
The function is missing doctests, which are required according to the project's CONTRIBUTING.md guidelines. All functions must include doctests that pass automated testing. Please add example test cases in the docstring showing the function's behavior with various inputs (e.g., positive even numbers, positive odd numbers, zero, and negative numbers).
| """ | ||
| Check whether a number is even. | ||
|
|
||
| :param n: Integer number | ||
| :return: True if even, False otherwise | ||
| """ |
There was a problem hiding this comment.
The docstring is missing a URL reference to Wikipedia or another similar explanation. According to the project's CONTRIBUTING.md, all new algorithms must include at least one URL that points to Wikipedia or another similar explanation. Consider adding a reference such as https://en.wikipedia.org/wiki/Parity_(mathematics) at the beginning of the docstring or as a module-level docstring.
| :param n: Integer number | ||
| :return: True if even, False otherwise | ||
| """ | ||
| return n % 2 == 0 |
There was a problem hiding this comment.
The file is missing the standard doctest execution block that is present in other similar files in the maths directory. Please add the following at the end of the file to enable doctest execution:
if name == "main":
import doctest
doctest.testmod()
There was a problem hiding this comment.
Click here to look at the relevant links ⬇️
🔗 Relevant Links
Repository:
Python:
Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.
algorithms-keeper commands and options
algorithms-keeper actions can be triggered by commenting on this PR:
@algorithms-keeper reviewto trigger the checks for only added pull request files@algorithms-keeper review-allto trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.
| @@ -0,0 +1,16 @@ | |||
| def is_even(n: int) -> bool: | |||
There was a problem hiding this comment.
Please provide descriptive name for the parameter: n
Describe your change:
Checklist: