diff --git a/.DS_Store b/.DS_Store
new file mode 100644
index 0000000..17b50c7
Binary files /dev/null and b/.DS_Store differ
diff --git a/README.md b/README.md
index 6445ffa..10a501b 100644
--- a/README.md
+++ b/README.md
@@ -1,93 +1,60 @@
-# Python.ScientificCalculator
+# Scientific Calculator
-## Description
-* **Objective** - To implement an `ScientificCalculator` which displays output of basic and scientific computations.
-* **Purpose** - To establish familiarity with:
- * Object `state`
- * Teamwork :+1:
+An interactive, command-line calculator written in Python. The application starts in `main.py`, where you can choose an arithmetic calculator or a scientific calculator.
+## Features
-## Git Collaboration
-* Click the `fork` button in the top right corner to create a copy of this repository on your github account.
- * You can go through the [GitHub forking tutorial](https://help.github.com/articles/fork-a-repo/) if you need additional practice with this.
-* You should work on this project in your own repository.
+### Arithmetic calculator
+- Addition, subtraction, multiplication, and division
+- Division-by-zero handling
+- Calculator display that updates after each successful operation
+- Memory controls:
+ - `M+` adds the displayed value to memory
+ - `MC` clears memory
+ - `MRC` recalls memory to the display
+
+### Scientific calculator
+
+Includes every arithmetic and memory feature, plus:
+
+- Powers, square roots, and reciprocals
+- Trigonometric functions: sine, cosine, and tangent
+- Inverse trigonometric functions: arcsine, arccosine, and arctangent
+- Trigonometric input and inverse-trigonometric results in degrees
+- Base-10 and natural logarithms
+- Factorials of non-negative integers
+- Symbolic differentiation and integration of expressions in `x`
+- Random integer generation within a supplied range
+- Mean, median, and mode for a comma-separated list of numbers
+- Input validation for invalid domains, such as negative square roots, zero reciprocals, and invalid logarithms
## Requirements
-### Testing
-
-* All features must be tested.
-* Tests must include normal behavior, and any possible error situations.
-* Tests must have descriptive names and should be independent of each other (running or not running one test should not influence the behavior of any other test).
-
-### Core Features
-* All calculators should have the following features:
- - A `state`, representing the value currently displayed on the calculator (default 0)
- - Get the current number on the display
- - Clear the display
- - Add, subtract, multiply, and divide the value on the `display` by a given number
- - Calculate the square (x2) and square root (√x) of the number on the display
- - Calculate variable exponentiation (xy)
- - Calculate the inverse of the number on the display (1/x)
- - Invert the sign of the number on the display (switch between positive and negative)
- - Update the display to `Err` if an error occurs (eg: Division by zero)
- - Errors must be cleared before any other operation can take place
-
-* Each operation should automatically update the display
-* YOU MAY NEED to break your code into several .py files so that you can do your `git` stuff easier.
-
-
-### Scientific Features
-
-- Switch display mode (binary, octal, decimal, hexadecimal)
- - `switchDisplayMode()` should rotate through the options
- - `switchDisplayMode(String mode)` should set the display to the mode given
-- Memory - Store up to one numeric value in memory for recall later (default to 0) *
- - (`M+` key) Add the currently displayed value to the value in memory (store in memory and update display) *
- - (`MC` key) Reset memory *
- - (`MRC` key) Recall the current value from memory to the display *
-- Trig functions
- - Sine - Calculate the sine of the displayed value and display it
- - Cosine - Calculate the cosine of the displayed value and display it
- - Tangent - Calculate the tangent of the displayed value and display it
- - Inverse Sine
- - Inverse Cosine
- - Inverse Tangent
-- Switch trig units mode (Degrees, Radians)
- - `switchUnitsMode()` should rotate through the options
- - `switchUnitsMode(String mode)` should set the trig units to the type given
-
-### Bonus
-- Factorial function
-- Logarithmic functions
- - Log
- - 10x (inverse logarithm)
- - Ln (natural logarithm)
- - ex (inverse natural logarithm)
-
-
-
-### Custom Features
-
-In addition to the Core and Scientific features, you are required to create at least two of your own features for the calculator. They can be any two features that are not already covered and that you can implement as you see fit. These features must be properly tested.
-
-### Hints
-
-The following functions should take the displayed value (x) and updated it according to the given formula: (this may not be an exhaustive list)
-
-- `square()`: x2
-- `squareRoot()`: √x
-- `inverse()`: 1/x
-- `switchSign()`: -x
-- `sine()`: sin(x)
-- `cosine()`: cos(x)
-- `tangent()`: tan(x)
-- `inverseSine()`: sin-1(x)
-- `inverseCosine()`: sin-1(x)
-- `inverseTangent()`: tan-1(x)
-- `factorial()`: x! (x factorial)
-
-## Submission
-
-Completed projects should be submitted by submitting a pull request against the [original repository](https://git.zipcode.rocks/Cohort4.2/ZCW-MacroLabs-OOP-ScientificCalculator). All work should be done in your own repository.
+- Python 3
+- [SymPy](https://www.sympy.org/) for symbolic differentiation and integration
+
+## Run the application
+
+If you are using the project virtual environment:
+
+```bash
+.venv/bin/python main.py
+```
+
+Otherwise, install the dependency in your active Python environment and run the program:
+
+```bash
+python3 -m pip install sympy
+python3 main.py
+```
+
+Follow the numbered prompts to select a calculator operation. Choose **3** from the main menu to exit.
+
+## Tests
+
+Run the current unit-test file with:
+
+```bash
+python3 calctests.py
+```
diff --git a/arithmetic_calculator.py b/arithmetic_calculator.py
new file mode 100644
index 0000000..b57a25a
--- /dev/null
+++ b/arithmetic_calculator.py
@@ -0,0 +1,56 @@
+import numbers
+
+
+class ArithmeticCalculator:
+ def __init__(self):
+ self.display = 0
+ self.memory = 0
+
+ def get_two_numbers(self):
+ a = float(input("First number: "))
+ b = float(input("Second number: "))
+ return a, b
+
+ def show_result(self, value):
+ self.display = value
+ print(f"\nResult = {self.display }\n")
+
+ def add(self):
+ a, b = self.get_two_numbers()
+ self.show_result(a + b)
+
+ def subtract(self):
+ a, b = self.get_two_numbers()
+ self.show_result(a - b)
+
+ def multiply(self):
+ a, b = self.get_two_numbers()
+ self.show_result(a * b)
+
+ def divide(self):
+ a, b = self.get_two_numbers()
+
+ if b == 0:
+ print("\nCannot divide by zero.\n")
+ return
+
+ self.show_result(a / b)
+
+ def memory_add(self):
+ if not isinstance(self.display, numbers.Number):
+ print("\nM+ requires a numeric value on the display.\n")
+ return
+
+ self.memory += self.display
+ self.display = self.memory
+
+ print(f"\nMemory = {self.memory}\n")
+
+ def memory_clear(self):
+ self.memory = 0
+ print("\nMemory cleared.\n")
+
+ def memory_recall(self):
+ self.display = self.memory
+ print(f"\nRecalled value = {self.display}\n")
+
diff --git a/calctests.py b/calctests.py
deleted file mode 100644
index 1964570..0000000
--- a/calctests.py
+++ /dev/null
@@ -1,25 +0,0 @@
-import unittest
-from calculator import Calculator
-
-
-class TestStringMethods(unittest.TestCase):
-
- def test_add(self):
- c = Calculator()
- self.assertEqual(c.add(3, 3), 6)
-
- def test_add2(self):
- c = Calculator()
- self.assertEqual(c.add(12, -10), 2)
-
- def test_add3(self):
- c = Calculator()
- self.assertEqual(c.add(5, 8), 13)
-
- def test_sub(self):
- c = Calculator()
- self.assertEqual(c.sub(9, 3), 6)
-
-
-if __name__ == '__main__':
- unittest.main()
diff --git a/calculator.py b/calculator.py
deleted file mode 100644
index 3c85ead..0000000
--- a/calculator.py
+++ /dev/null
@@ -1,12 +0,0 @@
-class Calculator:
-
- def __init__(self):
- pass
-
- def add(self, x, y):
- return x + y
-
- def sub(self, x, y):
- return 0
-
-# add lots more methods to this calculator class.
diff --git a/main-app.py b/main-app.py
deleted file mode 100644
index a7cc4e2..0000000
--- a/main-app.py
+++ /dev/null
@@ -1,34 +0,0 @@
-from calculator import Calculator
-
-
-def getTwoNumbers():
- a = float(input("first number? "))
- b = float(input("second number? "))
- return a, b
-
-
-def displayResult(x: float):
- print(x, "\n")
-
-
-def performCalcLoop(calc):
- while True:
- choice = input("Operation? ")
- if choice == 'q':
- break # user types q to quit calulator.
- elif choice == 'add':
- a, b = getTwoNumbers()
- displayResult(calc.add(a, b))
- else:
- print("That is not a valid input.")
-
-
-# main start
-def main():
- calc = Calculator()
- performCalcLoop(calc)
- print("Done Calculating.")
-
-
-if __name__ == '__main__':
- main()
diff --git a/main-app1.py b/main-app1.py
new file mode 100644
index 0000000..85924ab
--- /dev/null
+++ b/main-app1.py
@@ -0,0 +1,139 @@
+import math
+import sympy as sym
+
+def scientific_calculator():
+ while True:
+ print("\nScientific Calculator")
+ print("1. Addition")
+ print("2. Subtraction")
+ print("3. Multiplication")
+ print("4. Division")
+ print("5. Power")
+ print("6. Square Root")
+ print("7.Inverse")
+ print("8. Sine")
+ print("9. Cosine")
+ print("10. Tangent")
+ print("11. Log (base 10)")
+ print("12. Natural Log (ln)")
+ print("13. Factorial")
+ print("14. Differentiation")
+ print("15. Integration")
+ print("16. Exit")
+
+ choice = input("\nEnter your choice (1-15): ")
+
+
+ try:
+ if choice == "1":
+ a = int(input("Enter first number: "))
+ b = int(input("Enter second number: "))
+ Add = a + b
+ print(f"That's an arithmatic function\nThe Result = {Add}")
+
+ elif choice == "2":
+ a = float(input("Enter first number: "))
+ b = float(input("Enter second number: "))
+ Sub = a - b
+ print(f"That's an arithmatic function\nThe Result = {Sub}")
+
+ elif choice == "3":
+ a = float(input("Enter first number: "))
+ b = float(input("Enter second number: "))
+ Multiply = a * b
+ print(f"That's an arithmatic function\nThe Result = {Multiply}")
+
+ elif choice == "4":
+ a = float(input("Enter first number: "))
+ b = float(input("Enter second number: "))
+ if b == 0:
+ print("Error: Cannot divide by zero.")
+ else:
+ Divide = a / b
+ print(f"That's an arithmatic function\nThe Result = {Divide}")
+
+ elif choice == "5":
+ a = float(input("Enter base: "))
+ b = float(input("Enter exponent: "))
+ Power = a ** b
+ print(f"That's an exponential function\nThe Result = {Power}")
+
+ elif choice == "6":
+ a = float(input("Enter a number: "))
+ x = math.sqrt(a)
+ print(f"That's an exponential function\nThe Result = {x}")
+
+ elif choice == "7":
+ a = float(input("Enter a number: "))
+ Inverse = 1/a
+ print(f"That's an inverse function\nThe Result = {Inverse}")
+
+ elif choice == "8":
+ angle = float(input("Enter angle in degrees: "))
+ radians = math.radians(angle)
+ result = math.sin(radians)
+ print(f"That's a Sine function\nThe Result = {result}")
+
+ elif choice == "9":
+ angle = float(input("Enter angle in degrees: "))
+ radians = math.radians(angle)
+ result = math.cos(radians)
+ print(f"That's a Cosine function\nThe Result = {result}")
+
+ elif choice == "10":
+ angle = float(input("Enter angle in degrees: "))
+ radians = math.radians(angle)
+ result = math.tan(radians)
+ print(f"That's a Tan function\nThe Result = {result}")
+
+ elif choice == "11":
+ a = float(input("Enter a positive number: "))
+ if a <= 0:
+ print("Error: Logarithm is defined only for positive numbers.")
+ else:
+ result = math.log10(a)
+ print(f"That's a logarithmic function\nResult = {result}")
+
+ elif choice == "12":
+ a = float(input("Enter a positive number: "))
+ if a <= 0:
+ print("Error: Natural logarithm is defined only for positive numbers.")
+ else:
+ result = math.log(a)
+ print(f"That's a logarithmic function\nResult = {result}")
+
+ elif choice == "13":
+ n = int(input("Enter a non-negative integer: "))
+ if n < 0:
+ print("Error: Factorial is not defined for negative numbers.")
+ else:
+ result = math.factorial(x)
+ print(f"That's a Factorial function\nResult = {result}")
+
+ elif choice == "14":
+ x = sym.Symbol('x')
+ equation = (input("Enter funtion in x: "))
+ function = sym.sympify(equation)
+ derivative = sym.diff(function, x)
+ print(f"The Result = {derivative}")
+
+ elif choice == "15":
+ x = sym.Symbol('x')
+ equation = (input("Enter funtion in x: "))
+ function = sym.sympify(equation)
+ integral = sym.integrate(function, x)
+ print(f"The Result = {integral}")
+
+ elif choice == "16":
+ print("Thank you for using the calculator!")
+ break
+
+ else:
+ print("Invalid choice. Please select between 1 and 13.")
+
+ except ValueError:
+ print("Invalid input. Please enter numeric values.")
+
+
+scientific_calculator()
+
diff --git a/main.py b/main.py
new file mode 100644
index 0000000..6df7755
--- /dev/null
+++ b/main.py
@@ -0,0 +1,35 @@
+from menu import run_arithmetic_menu, run_scientific_menu
+
+
+def main():
+ while True:
+ print(
+ """
+Calculator Application
+
+1. Arithmetic Calculator
+2. Scientific Calculator
+3. Exit
+
+"""
+ )
+
+ choice = input("Enter your choice: ").strip()
+
+ if choice == "1":
+ run_arithmetic_menu()
+
+ elif choice == "2":
+ run_scientific_menu()
+
+ elif choice == "3":
+ print("\nProgram closed.\n")
+ break
+
+ else:
+ print("\nInvalid choice. Enter 1, 2, or 3.\n")
+
+
+if __name__ == "__main__":
+ main()
+
diff --git a/menu.py b/menu.py
new file mode 100644
index 0000000..46a442d
--- /dev/null
+++ b/menu.py
@@ -0,0 +1,189 @@
+import sympy as sym
+import random
+import statistics
+
+from arithmetic_calculator import ArithmeticCalculator
+from scientific_calculator import ScientificCalculator
+
+
+def run_arithmetic_menu():
+ calculator = ArithmeticCalculator()
+
+ while True:
+ print(
+ """
+Arithmetic Calculator
+
+1. Add
+2. Subtract
+3. Multiply
+4. Divide
+5. M+ - Add display value to memory
+6. MC - Clear memory
+7. MRC - Recall memory
+8. Return to Main Menu
+
+"""
+ )
+
+ choice = input("Enter your choice: ").strip()
+
+ try:
+ if choice == "1":
+ calculator.add()
+
+ elif choice == "2":
+ calculator.subtract()
+
+ elif choice == "3":
+ calculator.multiply()
+
+ elif choice == "4":
+ calculator.divide()
+
+ elif choice == "5":
+ calculator.memory_add()
+
+ elif choice == "6":
+ calculator.memory_clear()
+
+ elif choice == "7":
+ calculator.memory_recall()
+
+ elif choice == "8":
+ print("\nReturning to the main menu.\n")
+ break
+
+ else:
+ print("\nInvalid choice. Enter a number from 1 to 8.\n")
+
+ except ValueError as error:
+ print(f"\nInvalid numerical input: {error}\n")
+
+ except Exception as error:
+ print(f"\nError: {error}\n")
+
+
+def run_scientific_menu():
+ calculator = ScientificCalculator()
+
+ while True:
+ print(
+ """
+Scientific Calculator
+
+1. Add
+2. Subtract
+3. Multiply
+4. Divide
+5. Power
+6. Square Root
+7. Reciprocal
+8. Sine
+9. Cosine
+10. Tangent
+11. Inverse Sine
+12. Inverse Cosine
+13. Inverse Tangent
+14. Log Base 10
+15. Natural Log
+16. Factorial
+17. Differentiate
+18. Integrate
+19. Random number generator
+20. Mean, Median and Mode
+21. M+ - Add display value to memory
+22. MC - Clear memory
+23. MRC - Recall memory
+24. Return to Main Menu
+
+"""
+ )
+
+ choice = input("Enter your choice: ").strip()
+
+ try:
+ if choice == "1":
+ calculator.add()
+
+ elif choice == "2":
+ calculator.subtract()
+
+ elif choice == "3":
+ calculator.multiply()
+
+ elif choice == "4":
+ calculator.divide()
+
+ elif choice == "5":
+ calculator.power()
+
+ elif choice == "6":
+ calculator.square_root()
+
+ elif choice == "7":
+ calculator.inverse()
+
+ elif choice == "8":
+ calculator.sine()
+
+ elif choice == "9":
+ calculator.cosine()
+
+ elif choice == "10":
+ calculator.tangent()
+
+ elif choice == "11":
+ calculator.inverse_sine()
+
+ elif choice == "12":
+ calculator.inverse_cosine()
+
+ elif choice == "13":
+ calculator.inverse_tangent()
+
+ elif choice == "14":
+ calculator.log10()
+
+ elif choice == "15":
+ calculator.natural_log()
+
+ elif choice == "16":
+ calculator.factorial()
+
+ elif choice == "17":
+ calculator.differentiate()
+
+ elif choice == "18":
+ calculator.integrate()
+
+ elif choice == "19":
+ calculator.random_number()
+
+ elif choice == "20":
+ calculator.statistics_summary()
+
+ elif choice == "21":
+ calculator.memory_add()
+
+ elif choice == "22":
+ calculator.memory_clear()
+
+ elif choice == "23":
+ calculator.memory_recall()
+
+ elif choice == "24":
+ print("\nReturning to the main menu.\n")
+ break
+
+ else:
+ print("\nInvalid choice. Enter a number from 1 to 19.\n")
+
+ except ValueError as error:
+ print(f"\nInvalid numerical input: {error}\n")
+
+ except sym.SympifyError:
+ print("\nInvalid mathematical expression.\n")
+
+ except Exception as error:
+ print(f"\nError: {error}\n")
\ No newline at end of file
diff --git a/scientific_calculator.py b/scientific_calculator.py
new file mode 100644
index 0000000..2daf0de
--- /dev/null
+++ b/scientific_calculator.py
@@ -0,0 +1,169 @@
+import math
+import random
+import statistics
+import sympy as sym
+
+from arithmetic_calculator import ArithmeticCalculator
+
+
+class ScientificCalculator(ArithmeticCalculator):
+ def __init__(self):
+ super().__init__()
+
+ def power(self):
+ a, b = self.get_two_numbers()
+ self.show_result(a ** b)
+
+ def square_root(self):
+ number = float(input("Number: "))
+
+ if number < 0:
+ print(
+ "\nCannot calculate the real square root "
+ "of a negative number.\n"
+ )
+ return
+
+ self.show_result(math.sqrt(number))
+
+ def inverse(self):
+ number = float(input("Number: "))
+
+ if number == 0:
+ print("\nZero does not have a reciprocal.\n")
+ return
+
+ self.show_result(1 / number)
+
+ def sine(self):
+ angle = float(input("Angle in degrees: "))
+ radians = math.radians(angle)
+ self.show_result(math.sin(radians))
+
+ def cosine(self):
+ angle = float(input("Angle in degrees: "))
+ radians = math.radians(angle)
+ self.show_result(math.cos(radians))
+
+ def tangent(self):
+ angle = float(input("Angle in degrees: "))
+ radians = math.radians(angle)
+
+ if math.isclose(math.cos(radians), 0, abs_tol=1e-12):
+ print("\nTangent is undefined at this angle.\n")
+ return
+
+ self.show_result(math.tan(radians))
+
+ def inverse_sine(self):
+ value = float(input("Enter a value between -1 and 1: "))
+
+ if value < -1 or value > 1:
+ print("\nInput must be between -1 and 1.\n")
+ return
+
+ angle = math.degrees(math.asin(value))
+ self.show_result(angle)
+
+ def inverse_cosine(self):
+ value = float(input("Enter a value between -1 and 1: "))
+
+ if value < -1 or value > 1:
+ print("\nInput must be between -1 and 1.\n")
+ return
+
+ angle = math.degrees(math.acos(value))
+ self.show_result(angle)
+
+ def inverse_tangent(self):
+ value = float(input("Enter a number: "))
+
+ angle = math.degrees(math.atan(value))
+ self.show_result(angle)
+
+ def log10(self):
+ number = float(input("Positive number: "))
+
+ if number <= 0:
+ print("\nLogarithm requires a positive number.\n")
+ return
+
+ self.show_result(math.log10(number))
+
+ def natural_log(self):
+ number = float(input("Positive number: "))
+
+ if number <= 0:
+ print("\nNatural logarithm requires a positive number.\n")
+ return
+
+ self.show_result(math.log(number))
+
+ def factorial(self):
+ number = int(input("Non-negative integer: "))
+
+ if number < 0:
+ print("\nFactorial is not defined for negative integers.\n")
+ return
+
+ self.show_result(math.factorial(number))
+
+ def differentiate(self):
+ x = sym.Symbol("x")
+ expression = input("Enter a function in x: ")
+
+ function = sym.sympify(expression)
+ derivative = sym.diff(function, x)
+
+ self.show_result(derivative)
+
+ def integrate(self):
+ x = sym.Symbol("x")
+ expression = input("Enter a function in x: ")
+
+ function = sym.sympify(expression)
+ integral = sym.integrate(function, x)
+
+ self.show_result(integral)
+
+ def random_number(self):
+ minimum = int(input("Minimum integer: "))
+ maximum = int(input("Maximum integer: "))
+
+ if minimum > maximum:
+ print("\nMinimum cannot be greater than maximum.\n")
+ return
+
+ result = random.randint(minimum, maximum)
+ self.show_result(result)
+
+ def get_number_list(self):
+ user_input = input("Enter numbers separated by commas: ")
+ values = user_input.split(",")
+ number_list = []
+
+ for value in values:
+ number = float(value.strip())
+ number_list.append(number)
+
+ if not number_list:
+ raise ValueError("At least one number is required.")
+
+ return number_list
+
+ def statistics_summary(self):
+ numbers = self.get_number_list()
+
+ mean_value = statistics.mean(numbers)
+ median_value = statistics.median(numbers)
+ mode_values = statistics.multimode(numbers)
+
+ self.display = mean_value
+
+ print(f"\nMean = {mean_value}")
+ print(f"Median = {median_value}")
+
+ if len(mode_values) == 1:
+ print(f"Mode = {mode_values[0]}\n")
+ else:
+ print(f"Modes = {mode_values}\n")
\ No newline at end of file