-
Notifications
You must be signed in to change notification settings - Fork 0
Add utility functions #4
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
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 | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,4 +1,14 @@ | ||||||||||||
| # math_utils.py - Mathematical utility functions | ||||||||||||
| # math_utils.py - Statistical utility functions (feature-stats) | ||||||||||||
| def mean(numbers): | ||||||||||||
| return sum(numbers) / len(numbers) | ||||||||||||
|
|
||||||||||||
| def maximum(numbers): return max(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. Handle empty list to prevent ValueError. The function will raise 🛡️ Proposed fix with input validation-def maximum(numbers): return max(numbers)
+def maximum(numbers):
+ if not numbers:
+ raise ValueError("Cannot find maximum of empty list")
+ return max(numbers)The one-liner style is inconsistent with 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||
|
|
||||||||||||
| def minimum(numbers): return min(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. Handle empty list to prevent ValueError. The function will raise 🛡️ Proposed fix with input validation-def minimum(numbers): return min(numbers)
+def minimum(numbers):
+ if not numbers:
+ raise ValueError("Cannot find minimum of empty list")
+ return min(numbers)The one-liner style is inconsistent with 🤖 Prompt for AI Agents |
||||||||||||
|
|
||||||||||||
| def range_of(numbers): | ||||||||||||
| return max(numbers) - min(numbers) | ||||||||||||
| # math_utils.py - Mathematical utility functions (feature-math) | ||||||||||||
| def add(a, b): return a + b | ||||||||||||
|
|
||||||||||||
| def multiply(a, b): return a * b | ||||||||||||
|
|
@@ -10,4 +20,4 @@ def factorial(n): | |||||||||||
| return 1 | ||||||||||||
| result = 1 | ||||||||||||
| for i in range(1, n + 1): result *= i | ||||||||||||
| return result | ||||||||||||
| return result | ||||||||||||
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.
Handle empty list to prevent ZeroDivisionError.
The function will raise
ZeroDivisionErrorwhen called with an empty list. Add validation or consider usingstatistics.mean()from the standard library, which provides better error messages and handles edge cases.🛡️ Proposed fix with input validation
Alternatively, prefer the standard library implementation:
♻️ Alternative: Use statistics.mean
📝 Committable suggestion
🤖 Prompt for AI Agents