From bb2a2006797264a357d3de2242d48b25bb887239 Mon Sep 17 00:00:00 2001 From: Vdevannah Date: Fri, 10 Jul 2026 17:55:55 -0400 Subject: [PATCH 1/8] update readme --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 6445ffa..0d85a5c 100644 --- a/README.md +++ b/README.md @@ -91,3 +91,4 @@ The following functions should take the displayed value (x) and updated it accor ## 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. +vijay I am here \ No newline at end of file From ee2791eb9bc30353c52d4ca603ceaf7a6136d43f Mon Sep 17 00:00:00 2001 From: Vdevannah Date: Sat, 11 Jul 2026 11:46:09 -0400 Subject: [PATCH 2/8] Hey Team, see my progress --- calculator.py | 3 ++ main-app.py | 1 - main-app1.py | 117 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 120 insertions(+), 1 deletion(-) create mode 100644 main-app1.py diff --git a/calculator.py b/calculator.py index 3c85ead..c0736e9 100644 --- a/calculator.py +++ b/calculator.py @@ -1,3 +1,4 @@ + class Calculator: def __init__(self): @@ -10,3 +11,5 @@ 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 index a7cc4e2..b51521f 100644 --- a/main-app.py +++ b/main-app.py @@ -29,6 +29,5 @@ def main(): 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..d836334 --- /dev/null +++ b/main-app1.py @@ -0,0 +1,117 @@ +import math +import sympy as sym + +def scientific_calculator(): + while True: + print("\n===== Scientific Calculator =====") + print("1. Addition") + print("2. Subtraction") + print("3. Multiplication") + print("4. Division") + print("5. Power") + print("6. Square Root") + print("7. Sine") + print("8. Cosine") + print("9. Tangent") + print("10. Log (base 10)") + print("11. Natural Log (ln)") + print("12. Factorial") + print("13. Differentiate") + print("14. Integrate") + print("15. Exit") + + choice = input("\nEnter your choice (1-15): ") + + try: + if choice == "1": + a = float(input("Enter first number: ")) + b = float(input("Enter second number: ")) + Add = a + b + print(f"The Result = {Add}") + + elif choice == "2": + a = float(input("Enter first number: ")) + b = float(input("Enter second number: ")) + Sub = a - b + print(f"The Result = {Sub}") + + elif choice == "3": + a = float(input("Enter first number: ")) + b = float(input("Enter second number: ")) + Multiply = a * b + print(f"The 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"The Result = {Divide}") + + elif choice == "5": + a = float(input("Enter base: ")) + b = float(input("Enter exponent: ")) + print("Result =", math.pow(a, b)) + + elif choice == "6": + a = float(input("Enter a number: ")) + if a < 0: + print("Error: Square root of a negative number is not real.") + else: + print("Result =", math.sqrt(a)) + + elif choice == "7": + angle = float(input("Enter angle in degrees: ")) + print("Result =", math.sin(math.radians(angle))) + + elif choice == "8": + angle = float(input("Enter angle in degrees: ")) + print("Result =", math.cos(math.radians(angle))) + + elif choice == "9": + angle = float(input("Enter angle in degrees: ")) + print("Result =", math.tan(math.radians(angle))) + + elif choice == "10": + a = float(input("Enter a positive number: ")) + if a <= 0: + print("Error: Logarithm is defined only for positive numbers.") + else: + print("Result =", math.log10(a)) + + elif choice == "11": + a = float(input("Enter a positive number: ")) + if a <= 0: + print("Error: Natural logarithm is defined only for positive numbers.") + else: + print("Result =", math.log(a)) + + elif choice == "12": + n = int(input("Enter a non-negative integer: ")) + if n < 0: + print("Error: Factorial is not defined for negative numbers.") + else: + print("Result =", math.factorial(n)) + + elif choice == "13": + x = sym.Symbol('x') + expression = (input("Enter funtion in x: ")) + function = sym.sympify(expression) + derivative = sym.diff(function, x) + print(f"The Result = ", {derivative}) + + elif choice == "15": + 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() + From 56d208c58ee8cafb46bb023fb77276f2696f96b9 Mon Sep 17 00:00:00 2001 From: Vdevannah Date: Sat, 11 Jul 2026 14:06:51 -0400 Subject: [PATCH 3/8] changes_1 --- main-app1.py | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/main-app1.py b/main-app1.py index d836334..cc35a9d 100644 --- a/main-app1.py +++ b/main-app1.py @@ -44,23 +44,19 @@ def scientific_calculator(): 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 + Divide = a / b print(f"The Result = {Divide}") elif choice == "5": a = float(input("Enter base: ")) b = float(input("Enter exponent: ")) - print("Result =", math.pow(a, b)) + Power = a ** b + print(f"The Result = {Power}") elif choice == "6": a = float(input("Enter a number: ")) - if a < 0: - print("Error: Square root of a negative number is not real.") - else: - print("Result =", math.sqrt(a)) + x = math.sqrt(a) + print(f"The Result = {x}") elif choice == "7": angle = float(input("Enter angle in degrees: ")) From 75fff1bd2a319f5a8c6ded8449cf8bc2ff832d44 Mon Sep 17 00:00:00 2001 From: Vdevannah Date: Sat, 11 Jul 2026 14:14:00 -0400 Subject: [PATCH 4/8] Damere_changes --- main-app1.py | 86 ++++++++++++++++++++++++++++++++++------------------ 1 file changed, 56 insertions(+), 30 deletions(-) diff --git a/main-app1.py b/main-app1.py index cc35a9d..6c1ac36 100644 --- a/main-app1.py +++ b/main-app1.py @@ -3,102 +3,128 @@ def scientific_calculator(): while True: - print("\n===== Scientific Calculator =====") + print("\nScientific Calculator") print("1. Addition") print("2. Subtraction") print("3. Multiplication") print("4. Division") print("5. Power") print("6. Square Root") - print("7. Sine") - print("8. Cosine") - print("9. Tangent") - print("10. Log (base 10)") - print("11. Natural Log (ln)") - print("12. Factorial") - print("13. Differentiate") - print("14. Integrate") - print("15. Exit") + 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 = float(input("Enter first number: ")) - b = float(input("Enter second number: ")) + a = int(input("Enter first number: ")) + b = int(input("Enter second number: ")) Add = a + b - print(f"The Result = {Add}") + print(f"That's a 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"The Result = {Sub}") + print(f"That's a 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"The Result = {Multiply}") + print(f"That's a arithmatic function\nThe Result = {Multiply}") elif choice == "4": a = float(input("Enter first number: ")) b = float(input("Enter second number: ")) - Divide = a / b - print(f"The Result = {Divide}") + if b == 0: + print("Error: Cannot divide by zero.") + else: + Divide = a / b + print(f"That's a arithmatic function\nThe Result = {Divide}") elif choice == "5": a = float(input("Enter base: ")) b = float(input("Enter exponent: ")) Power = a ** b - print(f"The Result = {Power}") + print(f"That's a exponential function\nThe Result = {Power}") elif choice == "6": a = float(input("Enter a number: ")) x = math.sqrt(a) - print(f"The Result = {x}") + print(f"That's a exponential function\nThe Result = {x}") elif choice == "7": - angle = float(input("Enter angle in degrees: ")) - print("Result =", math.sin(math.radians(angle))) + a = float(input("Enter a number: ")) + Inverse = 1/a + print(f"That's a inverse function\nThe Result = {Inverse}") elif choice == "8": angle = float(input("Enter angle in degrees: ")) - print("Result =", math.cos(math.radians(angle))) + 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: ")) - print("Result =", math.tan(math.radians(angle))) + 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: - print("Result =", math.log10(a)) + result = math.log10(a) + print(f"That's a logarithmic function\nResult = {result}") - elif choice == "11": + elif choice == "12": a = float(input("Enter a positive number: ")) if a <= 0: print("Error: Natural logarithm is defined only for positive numbers.") else: - print("Result =", math.log(a)) + result = math.log(a) + print(f"That's a logarithmic function\nResult = {result}") - elif choice == "12": + elif choice == "13": n = int(input("Enter a non-negative integer: ")) if n < 0: print("Error: Factorial is not defined for negative numbers.") else: - print("Result =", math.factorial(n)) + result = math.factorial(x) + print(f"That's a Factorial function\nResult = {result}") - elif choice == "13": + elif choice == "14": x = sym.Symbol('x') expression = (input("Enter funtion in x: ")) function = sym.sympify(expression) derivative = sym.diff(function, x) - print(f"The Result = ", {derivative}) + print(f"The Result = {derivative}") elif choice == "15": + x = sym.Symbol('x') + expression = (input("Enter funtion in x: ")) + function = sym.sympify(expression) + derivative = sym.diff(function, x) + print(f"The Result = {derivative}") + + elif choice == "16": print("Thank you for using the calculator!") break From db1d2ae70eb31aa803bb7c500a911c8e162ab1c6 Mon Sep 17 00:00:00 2001 From: Vdevannah Date: Sat, 11 Jul 2026 14:44:11 -0400 Subject: [PATCH 5/8] New Change --- main-app1.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/main-app1.py b/main-app1.py index 6c1ac36..f9e7685 100644 --- a/main-app1.py +++ b/main-app1.py @@ -112,17 +112,17 @@ def scientific_calculator(): elif choice == "14": x = sym.Symbol('x') - expression = (input("Enter funtion in x: ")) - function = sym.sympify(expression) + 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') - expression = (input("Enter funtion in x: ")) - function = sym.sympify(expression) - derivative = sym.diff(function, x) - print(f"The Result = {derivative}") + 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!") From 5b3420f4da9d8a8c3a133cecbbb6474866d8b700 Mon Sep 17 00:00:00 2001 From: Vdevannah Date: Sun, 12 Jul 2026 11:39:08 -0400 Subject: [PATCH 6/8] This is a new scientific_calculator with classes and objects --- .DS_Store | Bin 0 -> 8196 bytes arithmetic_calculator.py | 56 +++++++++++++ main.py | 34 ++++++++ menu.py | 167 +++++++++++++++++++++++++++++++++++++++ scientific_calculator.py | 99 +++++++++++++++++++++++ 5 files changed, 356 insertions(+) create mode 100644 .DS_Store create mode 100644 arithmetic_calculator.py create mode 100644 main.py create mode 100644 menu.py create mode 100644 scientific_calculator.py diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..17b50c7467eaccb1747e338482f2f9decc1f6405 GIT binary patch literal 8196 zcmeHMYitx%6u#fIz>FPWS_>3pvRlh5SZoUwc?fPFyrdOmTl%25?(Pij$aJRe%x)>9 zro{Nbm}q<@{vtkqHfl6z42u3T@fA%&B8kMPiTKA~{J{kD+_|&F7WSV366YrOo_o$c z=iE7G&bfEbEMp9p zogpD$G)5kXJaDZCc-cHQF>`@{WthY=&|^7(-BtEAoQ6hRyp@hwWj~PSw6xsik%NSa2DM4iJf-U}g^LhvR@cj#p>*5njA;wfMs>5S?N)jU z!g4{ZR_~XU-mE)3OvZSE)~dJ5+L!XfeB+L^=kFOYo#G?4>N{n*-y2Hj%srzNtVM|q zSq@$-(YeSr!}8r+;Ee}sb-jCSHlYqMQ|IV^d7k$|xh1K=z(`LJ=YxH>s*tPPr-8w(5kk z5NT~AH9XVg|2pQsXXn_@>;k*UE@3t*pdp4;xEswBT5lfFl^gQ9OYs@id;n35xlb@d{qWNxV*R{}x65B;Lh)cpsnOG(N)_d>&-L6n?@l z_;p51cTSIKTr3^ag=EgLU1yLuiWxCo_$FXwV$T|0|8Fb({r@IBS+r&3fye_l$^$5G zPqw$xZlz8pUTepxKSG^1&Nm@oAVLFY;q;&!CwTP_Lz>6KwL}Of1f&&eH~d4ujr`#q R-T%@3AN(1fy5;Wwe*mshnePAq literal 0 HcmV?d00001 diff --git a/arithmetic_calculator.py b/arithmetic_calculator.py new file mode 100644 index 0000000..aef037c --- /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/main.py b/main.py new file mode 100644 index 0000000..5f405e2 --- /dev/null +++ b/main.py @@ -0,0 +1,34 @@ +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() \ No newline at end of file diff --git a/menu.py b/menu.py new file mode 100644 index 0000000..d415175 --- /dev/null +++ b/menu.py @@ -0,0 +1,167 @@ +import sympy as sym + +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. Log Base 10 +12. Natural Log +13. Factorial +14. Differentiate +15. Integrate +16. M+ - Add display value to memory +17. MC - Clear memory +18. MRC - Recall memory +19. 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.log10() + + elif choice == "12": + calculator.natural_log() + + elif choice == "13": + calculator.factorial() + + elif choice == "14": + calculator.differentiate() + + elif choice == "15": + calculator.integrate() + + elif choice == "16": + calculator.memory_add() + + elif choice == "17": + calculator.memory_clear() + + elif choice == "18": + calculator.memory_recall() + + elif choice == "19": + 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..128910c --- /dev/null +++ b/scientific_calculator.py @@ -0,0 +1,99 @@ +import math +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 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) \ No newline at end of file From 7047eb1bfe38c80d5d2f62308f72f29e296fde26 Mon Sep 17 00:00:00 2001 From: Vdevannah Date: Mon, 13 Jul 2026 10:12:37 -0400 Subject: [PATCH 7/8] Team, This is the final version --- README.md | 1 - arithmetic_calculator.py | 2 +- main-app1.py | 14 ++++---- main.py | 3 +- menu.py | 58 ++++++++++++++++++++++---------- scientific_calculator.py | 72 +++++++++++++++++++++++++++++++++++++++- 6 files changed, 121 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index 0d85a5c..6445ffa 100644 --- a/README.md +++ b/README.md @@ -91,4 +91,3 @@ The following functions should take the displayed value (x) and updated it accor ## 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. -vijay I am here \ No newline at end of file diff --git a/arithmetic_calculator.py b/arithmetic_calculator.py index aef037c..b57a25a 100644 --- a/arithmetic_calculator.py +++ b/arithmetic_calculator.py @@ -13,7 +13,7 @@ def get_two_numbers(self): def show_result(self, value): self.display = value - print(f"\nResult = {self.display}\n") + print(f"\nResult = {self.display }\n") def add(self): a, b = self.get_two_numbers() diff --git a/main-app1.py b/main-app1.py index f9e7685..85924ab 100644 --- a/main-app1.py +++ b/main-app1.py @@ -29,19 +29,19 @@ def scientific_calculator(): a = int(input("Enter first number: ")) b = int(input("Enter second number: ")) Add = a + b - print(f"That's a arithmatic function\nThe Result = {Add}") + 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 a arithmatic function\nThe Result = {Sub}") + 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 a arithmatic function\nThe Result = {Multiply}") + print(f"That's an arithmatic function\nThe Result = {Multiply}") elif choice == "4": a = float(input("Enter first number: ")) @@ -50,23 +50,23 @@ def scientific_calculator(): print("Error: Cannot divide by zero.") else: Divide = a / b - print(f"That's a arithmatic function\nThe Result = {Divide}") + 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 a exponential function\nThe Result = {Power}") + 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 a exponential function\nThe Result = {x}") + 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 a inverse function\nThe Result = {Inverse}") + print(f"That's an inverse function\nThe Result = {Inverse}") elif choice == "8": angle = float(input("Enter angle in degrees: ")) diff --git a/main.py b/main.py index 5f405e2..6df7755 100644 --- a/main.py +++ b/main.py @@ -31,4 +31,5 @@ def main(): if __name__ == "__main__": - main() \ No newline at end of file + main() + diff --git a/menu.py b/menu.py index d415175..46a442d 100644 --- a/menu.py +++ b/menu.py @@ -1,4 +1,6 @@ import sympy as sym +import random +import statistics from arithmetic_calculator import ArithmeticCalculator from scientific_calculator import ScientificCalculator @@ -80,15 +82,20 @@ def run_scientific_menu(): 8. Sine 9. Cosine 10. Tangent -11. Log Base 10 -12. Natural Log -13. Factorial -14. Differentiate -15. Integrate -16. M+ - Add display value to memory -17. MC - Clear memory -18. MRC - Recall memory -19. Return to Main Menu +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 """ ) @@ -125,32 +132,47 @@ def run_scientific_menu(): elif choice == "10": calculator.tangent() - + elif choice == "11": - calculator.log10() + calculator.inverse_sine() elif choice == "12": - calculator.natural_log() + calculator.inverse_cosine() elif choice == "13": - calculator.factorial() + calculator.inverse_tangent() elif choice == "14": - calculator.differentiate() + calculator.log10() elif choice == "15": - calculator.integrate() + calculator.natural_log() elif choice == "16": - calculator.memory_add() + calculator.factorial() elif choice == "17": - calculator.memory_clear() + calculator.differentiate() elif choice == "18": - calculator.memory_recall() + 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 diff --git a/scientific_calculator.py b/scientific_calculator.py index 128910c..2daf0de 100644 --- a/scientific_calculator.py +++ b/scientific_calculator.py @@ -1,4 +1,6 @@ import math +import random +import statistics import sympy as sym from arithmetic_calculator import ArithmeticCalculator @@ -52,6 +54,32 @@ def tangent(self): 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: ")) @@ -96,4 +124,46 @@ def integrate(self): function = sym.sympify(expression) integral = sym.integrate(function, x) - self.show_result(integral) \ No newline at end of file + 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 From 8d6855297162ce5a7808aaf3dfbafa578dae4212 Mon Sep 17 00:00:00 2001 From: Vdevannah Date: Mon, 13 Jul 2026 10:36:05 -0400 Subject: [PATCH 8/8] Final Calculator with READMe update --- README.md | 139 +++++++++++++++++++------------------------------- calctests.py | 25 --------- calculator.py | 15 ------ main-app.py | 33 ------------ 4 files changed, 53 insertions(+), 159 deletions(-) delete mode 100644 calctests.py delete mode 100644 calculator.py delete mode 100644 main-app.py 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/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 c0736e9..0000000 --- a/calculator.py +++ /dev/null @@ -1,15 +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 b51521f..0000000 --- a/main-app.py +++ /dev/null @@ -1,33 +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()