Add armstrong number checker by amandapanda00.#22
Open
amandapanda00 wants to merge 2 commits intoNeuroByte-Society:mainfrom
Open
Add armstrong number checker by amandapanda00.#22amandapanda00 wants to merge 2 commits intoNeuroByte-Society:mainfrom
amandapanda00 wants to merge 2 commits intoNeuroByte-Society:mainfrom
Conversation
main.py, test_main.py, numbers.txt, readme.md
ghostdeveloper404
requested changes
Dec 2, 2025
Contributor
There was a problem hiding this comment.
Hi @amandapanda00 — thanks for the contribution! I reviewed week1_projects/amandapanda00/armstrong_number_checker/main.py. Please make the following changes to improve correctness, robustness, and maintainability:
- Fix module docstring
- Change "sum of the cubes of its digits" to the general definition: an Armstrong number equals the sum of each digit raised to the power of the number of digits.
- Handle negative input
- Reject negative integers (return False) or explicitly document that only non-negative integers are supported. Current code will crash on negative input because of the '-' character in str(number).
Suggested change:
def is_armstrong(number: int) -> bool:
if number < 0:
return False
digits = [int(d) for d in str(number)]
n = len(digits)
return sum(d ** n for d in digits) == number
- Improve file handling
- Open files with explicit encoding (encoding="utf-8").
- Prefer pathlib.Path for clearer checks (exists/is_file).
- Keep existing FileNotFoundError/PermissionError handling but check path first to provide clearer messages.
- Make functions more testable
- Keep is_armstrong pure (it already is).
- Have process_result return the formatted string instead of printing directly; main() can print it. This makes unit testing easier.
- Input robustness and UX
- Catch KeyboardInterrupt and EOFError in main to exit gracefully.
- Validate filename input (strip and ignore empty input).
- Consider rejecting lines that contain non-digit characters (or handle leading '+') and report which lines are invalid.
- Clean up comments and add type hints
- Remove noisy inline comments like "# og had ** 3".
- Add type hints for public functions (e.g., process_file(filename: str) -> None).
- Improve docstrings (PEP 257 style).
- Tests and CI
- Add unit tests (pytest or unittest) covering:
- Typical Armstrong numbers: 153, 370, 9474
- Non-Armstrong numbers
- 0
- Negative values
- File input with invalid lines
- Consider adding a simple GitHub Actions workflow to run tests.
- Optional improvements (nice-to-have)
- Use argparse for CLI options (single number vs filename).
- Limit maximum allowed digits/value to avoid CPU/memory DoS from huge inputs and report if input is too large.
updated main, testing, and read me
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
main.py, test_main.py, numbers.txt, readme.md