Skip to content

Create calc.py #14

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

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open

Create calc.py #14

wants to merge 4 commits into from

Conversation

PavelLinearB
Copy link
Contributor

@PavelLinearB PavelLinearB commented Mar 6, 2025

workerB

✨ PR Description

Purpose: Implements a basic command-line calculator with four arithmetic operations and input validation.

Main changes:

  • Added four basic arithmetic functions (add, subtract, multiply, divide)
  • Implemented interactive user input loop with operation selection and number input
  • Added error handling for invalid inputs and option to perform multiple calculations

Generated by LinearB AI and added by gitStream.
AI-generated content may contain inaccuracies. Please verify before using. We’d love your feedback! 🚀

@PavelLinearB PavelLinearB changed the base branch from calculator-app to develop March 6, 2025 16:50
Copy link

gitstream-cm bot commented Mar 6, 2025

 /:\ gitStream DRY RUN 

gitstream/estimated_time_to_review

• add label 1 min review with color 36A853

To activate these actions - merge this PR into the main branch


Learn more on the gitStream Docs
See your automations on the Usage in LinearB
Create new rules on the gitSteam playground

Copy link

gitstream-cm bot commented Mar 6, 2025

✨ PR Review

Security - calc/calc.py

Details:

Problem: No handling of division by zero, which could crash the program
Fix: Add zero check in divide function and handle the error case
Why: Prevents program crashes and provides better user experience

@@ -13,7 +13,10 @@

# This function divides two numbers
def divide(x, y):
-    return x / y
+    if y == 0:
+        raise ValueError("Cannot divide by zero")
+    else:
+        return x / y

print("Select operation.")
print("1.Add")
@@ -42,7 +45,11 @@
            print(num1, "*", num2, "=", multiply(num1, num2))

        elif choice == '4':
-            print(num1, "/", num2, "=", divide(num1, num2))
+            try:
+                print(num1, "/", num2, "=", divide(num1, num2))
+            except ValueError as e:
+                print(e)
+                continue

Maintainability - calc/calc.py

Details:

Problem: User input validation for next_calculation is case-sensitive and doesn't handle whitespace
Fix: Add case-insensitive comparison and strip whitespace
Why: Improves user experience by being more forgiving with input formatting

@@ -47,7 +47,7 @@
        # check if user wants another calculation
        # break the while loop if answer is no
        next_calculation = input("Let's do next calculation? (yes/no): ")
-        if next_calculation == "no":
+        if next_calculation.strip().lower() == "no":
          break
    else:
        print("Invalid Input")

Generated by LinearB AI and added by gitStream.
AI-generated content may contain inaccuracies. Please verify before using. We’d love your feedback! 🚀

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

Successfully merging this pull request may close these issues.

1 participant