Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions SimpleCalculator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
def add(a, b):
return a + b

def subtract(a, b):
return a - b

def multiply(a, b):
return a * b

def divide(a, b):
if b == 0:
return "Error! Division by zero."
Comment on lines +10 to +12
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (bug_risk): Returning a string on division by zero may lead to inconsistent return types.

Recommend raising an exception or returning None to maintain consistent numeric return types.

return a / b
Comment on lines +11 to +13
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (code-quality): We've found these issues:

Suggested change
if b == 0:
return "Error! Division by zero."
return a / b
return "Error! Division by zero." if b == 0 else a / b


print("Simple Calculator")
print("Addition:", add(5, 3))
print("Subtraction:", subtract(5, 3))
print("Multiplication:", multiply(5, 3))
print("Division:", divide(5, 3))
Comment on lines +15 to +19
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Directly invoking print statements at the module level can cause side effects on import.

Wrap the print statements in an if name == "main": block to avoid side effects when importing this module.