-
Notifications
You must be signed in to change notification settings - Fork 1
Add math utilities module #30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
2d65dca
b072799
e9c6245
71b543d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,56 @@ | ||||||||||||||||||||||||||
| def add(a, b): | ||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Guideline violation: The project requires every Python function to have a docstring explaining its purpose, parameters, and return value. None of the functions in this file have docstrings — this applies to all 11 functions including the two added in this commit.
|
||||||||||||||||||||||||||
| return a + b | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| def subtract(a, b): | ||||||||||||||||||||||||||
| return a - b | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| def multiply(a, b): | ||||||||||||||||||||||||||
| return a * b | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| def divide(a, b): | ||||||||||||||||||||||||||
| if b == 0: | ||||||||||||||||||||||||||
| raise ValueError("Cannot divide by zero") | ||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing test coverage: No test covers the
|
||||||||||||||||||||||||||
| return a / b | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| def power(base, exponent): | ||||||||||||||||||||||||||
| return base ** exponent | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| def is_even(n): | ||||||||||||||||||||||||||
| return n % 2 == 0 | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| def factorial(n): | ||||||||||||||||||||||||||
| if n < 0: | ||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing test coverage: Three scenarios lack tests:
Unit tests for each of these would protect against regressions.
|
||||||||||||||||||||||||||
| raise ValueError("Factorial not defined for negative numbers") | ||||||||||||||||||||||||||
| if n == 0: | ||||||||||||||||||||||||||
| return 1 | ||||||||||||||||||||||||||
| return n * factorial(n - 1) | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
|
Comment on lines
+28
to
+33
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: This recursive implementation will raise
Suggested change
|
||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| def clamp(value, min_val, max_val): | ||||||||||||||||||||||||||
| return max(min_val, min(max_val, value)) | ||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: When Trace through
The function returns
Suggested change
|
||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| def average(numbers): | ||||||||||||||||||||||||||
| if not numbers: | ||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing test coverage: No test covers the
|
||||||||||||||||||||||||||
| raise ValueError("Cannot compute average of empty list") | ||||||||||||||||||||||||||
| return sum(numbers) / len(numbers) | ||||||||||||||||||||||||||
| # Trigger review | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing test coverage: No test covers the
|
||||||||||||||||||||||||||
| def percentage(value, total): | ||||||||||||||||||||||||||
| if total == 0: | ||||||||||||||||||||||||||
| raise ValueError("total cannot be zero") | ||||||||||||||||||||||||||
| return (value / total) * 100 | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| def is_prime(n): | ||||||||||||||||||||||||||
| if n < 2: | ||||||||||||||||||||||||||
| return False | ||||||||||||||||||||||||||
| for i in range(2, int(n**0.5) + 1): | ||||||||||||||||||||||||||
| if n % i == 0: | ||||||||||||||||||||||||||
| return False | ||||||||||||||||||||||||||
| return True | ||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Logic duplication:
add,subtract,multiply, anddivideare already implemented incalculator.pywith identical logic. A future change to division behavior (e.g. returningNoneinstead of raising, or adding float-rounding rules) would require updating both files. Either remove these four functions and import fromcalculator.py, or consolidate both modules into one.