Skip to content

Conversation

@Aman-Mishra-Exarrow
Copy link

@Aman-Mishra-Exarrow Aman-Mishra-Exarrow commented Jan 15, 2026

Added a new calculator app in python

Summary by CodeRabbit

  • New Features
    • Added a calculator with basic arithmetic operations (addition, subtraction, multiplication, division).
    • Introduced an interactive menu interface for selecting operations and inputting values.
    • Implemented error handling for invalid division scenarios.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Jan 15, 2026

📝 Walkthrough

Walkthrough

A new Calculator.py module is introduced containing four arithmetic functions (add, subtract, multiply, divide) with division-by-zero protection, paired with an interactive command-line interface that prompts users for operation selection and operands.

Changes

Cohort / File(s) Summary
New Calculator Module
Calculator.py
Added four arithmetic functions: add(), subtract(), multiply(), divide() with zero-division error handling; integrated interactive CLI with operation menu and user input processing (36 lines)

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A calculator born, with functions so neat,
Add, subtract, multiply—operations complete!
With divide by zero safely caught by the guard,
And a menu for users (just a hop, not hard),
A rabbit approves of this math-filled delight! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Adding calculator app' directly matches the PR description and accurately summarizes the main change—introducing a new calculator application with four basic arithmetic operations and an interactive CLI.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In `@Calculator.py`:
- Around line 24-25: The conversions to float for num1 and num2 lack validation
and will raise ValueError on non-numeric input; change the logic so you
repeatedly prompt until a valid float is entered (e.g., implement a helper like
get_float_input(prompt) that wraps float(input(...)) in a try/except ValueError
loop and returns a float), and replace the direct assignments to num1 and num2
with calls to that helper so invalid input is handled gracefully instead of
crashing.
- Around line 16-36: The CLI block runs at import time; wrap the interactive
prompt and choice-handling logic inside a main guard by moving the printed menu,
input() calls, and the if/elif chain that calls add, subtract, multiply, divide
into a function (e.g., main()) and call that function only under if __name__ ==
"__main__": so importing Calculator won't execute the prompts.
🧹 Nitpick comments (1)
Calculator.py (1)

10-13: Mixed return type in divide() is problematic.

The function returns either a float or a str, which can cause issues for callers who expect a numeric result. Consider raising a ValueError or ZeroDivisionError instead, or returning None for error cases.

♻️ Suggested fix: raise an exception for consistency
 def divide(a, b):
     if b == 0:
-        return "Error: Division by zero"
+        raise ZeroDivisionError("Cannot divide by zero")
     return a / b

Then update the caller to handle the exception:

elif choice == "4":
    try:
        print("Result:", divide(num1, num2))
    except ZeroDivisionError as e:
        print("Error:", e)
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 707e5c6 and 1ec3ea6.

📒 Files selected for processing (1)
  • Calculator.py
🔇 Additional comments (1)
Calculator.py (1)

1-8: LGTM!

The add, subtract, and multiply functions are clean and correct implementations.

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.

Comment on lines +16 to +36
print("=== Simple Calculator ===")
print("1. Add")
print("2. Subtract")
print("3. Multiply")
print("4. Divide")

choice = input("Enter choice (1/2/3/4): ")

num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))

if choice == "1":
print("Result:", add(num1, num2))
elif choice == "2":
print("Result:", subtract(num1, num2))
elif choice == "3":
print("Result:", multiply(num1, num2))
elif choice == "4":
print("Result:", divide(num1, num2))
else:
print("Invalid choice") No newline at end of file
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Missing if __name__ == "__main__": guard.

The CLI code executes immediately when the module is loaded. This prevents reusing the functions via import Calculator without triggering the interactive prompts.

🛠️ Wrap CLI in main guard
+def main():
+    print("=== Simple Calculator ===")
+    print("1. Add")
+    print("2. Subtract")
+    print("3. Multiply")
+    print("4. Divide")
+
+    choice = input("Enter choice (1/2/3/4): ")
+
+    num1 = float(input("Enter first number: "))
+    num2 = float(input("Enter second number: "))
+
+    if choice == "1":
+        print("Result:", add(num1, num2))
+    elif choice == "2":
+        print("Result:", subtract(num1, num2))
+    elif choice == "3":
+        print("Result:", multiply(num1, num2))
+    elif choice == "4":
+        print("Result:", divide(num1, num2))
+    else:
+        print("Invalid choice")
+
+if __name__ == "__main__":
+    main()
-print("=== Simple Calculator ===")
-print("1. Add")
-print("2. Subtract")
-print("3. Multiply")
-print("4. Divide")
-
-choice = input("Enter choice (1/2/3/4): ")
-
-num1 = float(input("Enter first number: "))
-num2 = float(input("Enter second number: "))
-
-if choice == "1":
-    print("Result:", add(num1, num2))
-elif choice == "2":
-    print("Result:", subtract(num1, num2))
-elif choice == "3":
-    print("Result:", multiply(num1, num2))
-elif choice == "4":
-    print("Result:", divide(num1, num2))
-else:
-    print("Invalid choice")
🤖 Prompt for AI Agents
In `@Calculator.py` around lines 16 - 36, The CLI block runs at import time; wrap
the interactive prompt and choice-handling logic inside a main guard by moving
the printed menu, input() calls, and the if/elif chain that calls add, subtract,
multiply, divide into a function (e.g., main()) and call that function only
under if __name__ == "__main__": so importing Calculator won't execute the
prompts.

Comment on lines +24 to +25
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

No input validation for numeric conversion.

float() will raise ValueError if the user enters non-numeric input, crashing the program. Wrap in try/except for a better user experience.

🛠️ Add input validation
-num1 = float(input("Enter first number: "))
-num2 = float(input("Enter second number: "))
+try:
+    num1 = float(input("Enter first number: "))
+    num2 = float(input("Enter second number: "))
+except ValueError:
+    print("Invalid input. Please enter numeric values.")
+    exit(1)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
try:
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
except ValueError:
print("Invalid input. Please enter numeric values.")
exit(1)
🤖 Prompt for AI Agents
In `@Calculator.py` around lines 24 - 25, The conversions to float for num1 and
num2 lack validation and will raise ValueError on non-numeric input; change the
logic so you repeatedly prompt until a valid float is entered (e.g., implement a
helper like get_float_input(prompt) that wraps float(input(...)) in a try/except
ValueError loop and returns a float), and replace the direct assignments to num1
and num2 with calls to that helper so invalid input is handled gracefully
instead of crashing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant