-
Notifications
You must be signed in to change notification settings - Fork 0
Update calculator.py #19
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 | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -14,3 +14,8 @@ def divide(x, y): | |||||||||||||||||||||||||||||||||
| if y == 0: | ||||||||||||||||||||||||||||||||||
| return 'Cannot divide by 0' | ||||||||||||||||||||||||||||||||||
| return x * 1.0 / y | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| def divide2(x, y): | ||||||||||||||||||||||||||||||||||
| if y == 0: | ||||||||||||||||||||||||||||||||||
|
Comment on lines
14
to
+19
Owner
Author
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. Both division methods mix return types (string for error case, float for success). This is not a recommended practice in Python. Consider using exception handling instead of returning error strings. This makes the function's contract clearer and allows for proper error handling by callers. |
||||||||||||||||||||||||||||||||||
| return 'Cannot divide by 0' | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+19
to
+20
Owner
Author
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. Consider using a more robust error handling approach. Returning a string for error cases while returning numbers for successful cases creates inconsistent return types, which can lead to type-related bugs. Consider raising a
Suggested change
Comment on lines
+19
to
+20
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. Returning a string for error conditions is inconsistent with typical Python practices and creates type safety issues. Consider raising a
Suggested change
|
||||||||||||||||||||||||||||||||||
| return x * 1.0 / y | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+18
to
+21
Owner
Author
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. This method is an exact duplicate of the existing
Comment on lines
+18
to
+21
Owner
Author
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. This function appears to be an exact duplicate of the existing
Comment on lines
+18
to
+21
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. This function is an exact duplicate of the existing
Comment on lines
+18
to
+21
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. The function indentation appears incorrect. Based on the diff context, this function should be at the module level (same indentation as other functions), not nested inside another function.
Suggested change
Comment on lines
+18
to
+21
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. This method is an exact duplicate of the existing
If this was added accidentally, please remove it.
Comment on lines
+18
to
+21
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. The indentation appears to be incorrect. Based on the existing code structure, this method should be indented to align with other class methods. The current indentation suggests this might not be properly part of the Calculator class.
Suggested change
|
||||||||||||||||||||||||||||||||||
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.
The new
divide2method appears to be a duplicate of the existingdividemethod. Having duplicate code increases maintenance burden and potential for bugs. If there's a specific reason for having a second division method, it should be clearly documented. Otherwise, this addition should be removed.