Skip to content
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

Calculator app fixed #10

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

Calculator app fixed #10

wants to merge 3 commits into from

Conversation

PavelLinearB
Copy link
Member

@PavelLinearB PavelLinearB commented Feb 19, 2025

✨ PR Description

Purpose: Creates a basic calculator application with a command-line interface supporting addition, subtraction, multiplication, and division operations.

Main changes:

  • Implements four basic arithmetic functions with error handling for division by zero
  • Creates an interactive loop for user input with operation selection and number entry
  • Adds input validation and option to perform multiple calculations consecutively

Generated by LinearB AI and added by gitStream

@PavelLinearB PavelLinearB changed the title Calculator app fixed Calculator app fixed Feb 20, 2025
Copy link

gitstream-cm bot commented Feb 20, 2025

✨ PR Review

Maintainability - calc/calc.py (Lines 1-57)

Details:

Problem: Main program logic mixed with function definitions, making the code harder to maintain and test.
Fix: Separate the main program logic into a main() function and use if __name__ == "__main__":
Why: Improves code organization, testability, and reusability by separating function definitions from execution logic

# Calculator functions remain the same...

+def main():
    print("Select operation.")
    print("1.Add")
    print("2.Subtract")
    print("3.Multiply")
    print("4.Divide")

    while True:
        # Rest of the main program logic...

+if __name__ == "__main__":
+    main()

Error Handling - calc/calc.py (Lines 13-17)

Details:

Problem: Division error handling doesn't catch float division errors
Fix: Add try-except block in the divide function to handle all potential division errors
Why: More robust error handling for different types of division errors

def divide(x, y):
    if y == 0:
        raise ValueError("Cannot divide by zero")
-    return x / y
+    try:
+        return x / y
+    except (ArithmeticError, OverflowError) as e:
+        raise ValueError(f"Division error: {str(e)}")

Maintainability - calc/calc.py (Lines 47-51)

Details:

Problem: No validation for next_calculation input could lead to unexpected behavior
Fix: Add proper input validation for the continuation prompt
Why: Improves robustness and user experience by handling invalid inputs properly

-        next_calculation = input("Let's do next calculation? (yes/no): ")
-        if next_calculation.lower() == "no":
-          break
+        while True:
+            next_calculation = input("Let's do next calculation? (yes/no): ").lower()
+            if next_calculation in ('yes', 'no'):
+                if next_calculation == 'no':
+                    break
+                break
+            print("Please enter 'yes' or 'no'")

Generated by LinearB AI and added by gitStream

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