From 466a9f72a1429f75d2efcd5f109e2c4ff52c34eb Mon Sep 17 00:00:00 2001 From: Nathan Ingram Date: Sat, 28 Feb 2026 13:12:54 -0500 Subject: [PATCH 01/23] Create Display functions This is where all the calculators display functions will live! Godspeed --- Display functions | 1 + 1 file changed, 1 insertion(+) create mode 100644 Display functions diff --git a/Display functions b/Display functions new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/Display functions @@ -0,0 +1 @@ + From 90bc2dc4f8dfac9e5ad5c27eac02577d10372e6e Mon Sep 17 00:00:00 2001 From: david Date: Sat, 28 Feb 2026 13:16:45 -0500 Subject: [PATCH 02/23] change to .py --- Display functions => Display functions.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Display functions => Display functions.py (100%) diff --git a/Display functions b/Display functions.py similarity index 100% rename from Display functions rename to Display functions.py From ffce5ce57d12129ec43e64cfcb08a7c39204c267 Mon Sep 17 00:00:00 2001 From: james Date: Sat, 28 Feb 2026 13:22:42 -0500 Subject: [PATCH 03/23] Subtraction corrected. Multiplication and Addition created. --- calctests.py | 6 ++++++ calculator.py | 8 +++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/calctests.py b/calctests.py index 1964570..625c156 100644 --- a/calctests.py +++ b/calctests.py @@ -20,6 +20,12 @@ def test_sub(self): c = Calculator() self.assertEqual(c.sub(9, 3), 6) + def test_mult(self): + c = Calculator() + self.assertEqual(c.mult(9, 3), 27) + def test_div(self): + c = Calculator() + self.assertEqual(c.div(9, 3), 3) if __name__ == '__main__': unittest.main() diff --git a/calculator.py b/calculator.py index 3c85ead..b554947 100644 --- a/calculator.py +++ b/calculator.py @@ -7,6 +7,12 @@ def add(self, x, y): return x + y def sub(self, x, y): - return 0 + return x -y + + def mult(self, x, y): + return x * y + + def div(self, x, y): + return x / y # add lots more methods to this calculator class. From 6741de2fcc3df97e5b5e075facd3d91b459a345f Mon Sep 17 00:00:00 2001 From: james Date: Sat, 28 Feb 2026 14:49:24 -0500 Subject: [PATCH 04/23] Added exponentiation and square roots. --- calctests.py | 14 ++++++++++++++ calculator.py | 10 ++++++++++ 2 files changed, 24 insertions(+) diff --git a/calctests.py b/calctests.py index 625c156..6a8ad29 100644 --- a/calctests.py +++ b/calctests.py @@ -1,3 +1,4 @@ +import math import unittest from calculator import Calculator @@ -27,5 +28,18 @@ def test_mult(self): def test_div(self): c = Calculator() self.assertEqual(c.div(9, 3), 3) + + def test_div(self): + c = Calculator() + self.assertEqual(c.sqr(9), 81) + + def test_root2(self): + c = Calculator() + self.assertEqual(c.root2(9), 3) + + def test_exp(self): + c = Calculator() + self.assertEqual(c.exp(9,3), 729) + if __name__ == '__main__': unittest.main() diff --git a/calculator.py b/calculator.py index b554947..b6d2c94 100644 --- a/calculator.py +++ b/calculator.py @@ -1,3 +1,5 @@ +import math + class Calculator: def __init__(self): @@ -14,5 +16,13 @@ def mult(self, x, y): def div(self, x, y): return x / y + + def sqr(self, x): + return x * x + def root2(self, x): + return math.sqrt(x) + + def exp(self, x, y): + return math.pow(x, y) # add lots more methods to this calculator class. From a561363fceb9b0e98d2c7036b4499669557aedb6 Mon Sep 17 00:00:00 2001 From: james Date: Sat, 28 Feb 2026 15:10:24 -0500 Subject: [PATCH 05/23] Added Inversion and Negation. --- calctests.py | 12 ++++++++++++ calculator.py | 6 ++++++ 2 files changed, 18 insertions(+) diff --git a/calctests.py b/calctests.py index 6a8ad29..9e8a68a 100644 --- a/calctests.py +++ b/calctests.py @@ -41,5 +41,17 @@ def test_exp(self): c = Calculator() self.assertEqual(c.exp(9,3), 729) + def inv(self): + c = Calculator() + self.assertEqual(c.inv(5), .2) + + def neg(self): + c = Calculator() + self.assertEqual(c.neg(9), -9) + + def neg(self): + c = Calculator() + self.assertEqual(c.neg(-9), 9) + if __name__ == '__main__': unittest.main() diff --git a/calculator.py b/calculator.py index b6d2c94..8400d01 100644 --- a/calculator.py +++ b/calculator.py @@ -25,4 +25,10 @@ def root2(self, x): def exp(self, x, y): return math.pow(x, y) + + def inv(self, x): + return x ** -1 + + def neg(self, x): + return x * -1 # add lots more methods to this calculator class. From 31224edd081167d3fa53d389c512771713a74eab Mon Sep 17 00:00:00 2001 From: james Date: Sat, 28 Feb 2026 15:50:22 -0500 Subject: [PATCH 06/23] Added Sine, Cosine, Tangent, and each of their inverses. --- calctests.py | 26 ++++++++++++++++++++++++++ calculator.py | 19 +++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/calctests.py b/calctests.py index 9e8a68a..7db21ba 100644 --- a/calctests.py +++ b/calctests.py @@ -53,5 +53,31 @@ def neg(self): c = Calculator() self.assertEqual(c.neg(-9), 9) + def sin(self): + c = Calculator() + self.assertEqual(c.neg(9), 0.4121184852417566) + + def cos(self): + c = Calculator() + self.assertEqual(c.neg(9), -0.9111302618846769) + + def tan(self): + c = Calculator() + self.assertEqual(c.neg(9), 0.4523156594418099) + + def isin(self): + c = Calculator() + self.assertEqual(c.neg(-1), -1.5707963267948966) + + def icos(self): + c = Calculator() + self.assertEqual(c.neg(-1), 3.141592653589793) + + def itanmath(self): + c = Calculator() + self.assertEqual(c.neg(-1), -0.7853981633974483) + + + if __name__ == '__main__': unittest.main() diff --git a/calculator.py b/calculator.py index 8400d01..431a91f 100644 --- a/calculator.py +++ b/calculator.py @@ -31,4 +31,23 @@ def inv(self, x): def neg(self, x): return x * -1 + + def sin(self, x): + return math.sin(x) + + def cos(self, x): + return math.cos(x) + + def tan(self, x): + return math.tan(x) + + def isin(self, x): + return math.asin(x) + + def icos(self, x): + return math.acos(x) + + def itan(self, x): + return math.atan(x) + # add lots more methods to this calculator class. From 560eb9ff4a94f76e123f3cbdcb2951b6b96bad14 Mon Sep 17 00:00:00 2001 From: james Date: Sat, 28 Feb 2026 16:23:12 -0500 Subject: [PATCH 07/23] Corrected syntax on trigonmetric functions and their inverses (sine, cosine, tangent, arc sine, arc cosine, and arc tangent), and added code for degree conversion, radian conversion, factorial, and logarithm. --- calctests.py | 30 +++++++++++++++++++++++------- calculator.py | 12 ++++++++++++ 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/calctests.py b/calctests.py index 7db21ba..726912f 100644 --- a/calctests.py +++ b/calctests.py @@ -55,27 +55,43 @@ def neg(self): def sin(self): c = Calculator() - self.assertEqual(c.neg(9), 0.4121184852417566) + self.assertEqual(c.sin(9), 0.4121184852417566) def cos(self): c = Calculator() - self.assertEqual(c.neg(9), -0.9111302618846769) + self.assertEqual(c.cos(9), -0.9111302618846769) def tan(self): c = Calculator() - self.assertEqual(c.neg(9), 0.4523156594418099) + self.assertEqual(c.tan(9), 0.4523156594418099) def isin(self): c = Calculator() - self.assertEqual(c.neg(-1), -1.5707963267948966) + self.assertEqual(c.isin(-1), -1.5707963267948966) def icos(self): c = Calculator() - self.assertEqual(c.neg(-1), 3.141592653589793) + self.assertEqual(c.icos(-1), 3.141592653589793) - def itanmath(self): + def itan(self): c = Calculator() - self.assertEqual(c.neg(-1), -0.7853981633974483) + self.assertEqual(c.itan(-1), -0.7853981633974483) + + def deg(self): + c = Calculator() + self.assertEqual(c.deg(45), 2578.3100780887044) + + def rad(self): + c = Calculator() + self.assertEqual(c.rad(45), 0.7853981633974483) + + def fac(self): + c = Calculator() + self.assertEqual(c.fac(9), 362880) + + def log(self): + c = Calculator() + self.assertEqual(c.log(9), 2.1972245773362196) diff --git a/calculator.py b/calculator.py index 431a91f..effdd22 100644 --- a/calculator.py +++ b/calculator.py @@ -50,4 +50,16 @@ def icos(self, x): def itan(self, x): return math.atan(x) + def deg(self, x): + return math.degrees(x) + + def rad(self, x): + return math.radians(x) + + def fac(self, x): + return math.factorial(x) + + def log(self, x): + return math.log(x) + # add lots more methods to this calculator class. From 3c931844f003daaddb1b4b36642b1b1975219610 Mon Sep 17 00:00:00 2001 From: nate Date: Sat, 28 Feb 2026 16:40:11 -0500 Subject: [PATCH 08/23] Created display modes to switch between for Binary, Hexadecimal, decimal, and octal. Also added Display functions to allow saving previous saved file --- Display functions.py | 1 - Display_functions.py | 29 +++++++++++++++++++++++++++++ main-app.py | 33 ++++++++++++++++++++++++++------- 3 files changed, 55 insertions(+), 8 deletions(-) delete mode 100644 Display functions.py create mode 100644 Display_functions.py diff --git a/Display functions.py b/Display functions.py deleted file mode 100644 index 8b13789..0000000 --- a/Display functions.py +++ /dev/null @@ -1 +0,0 @@ - diff --git a/Display_functions.py b/Display_functions.py new file mode 100644 index 0000000..030c330 --- /dev/null +++ b/Display_functions.py @@ -0,0 +1,29 @@ +class Display: + def store_memory(self, value, memory_value, current_result): + # Code to store the value in memory + if value.lower() == "m+": + memory_value = current_result + print(f"Current memory value: {memory_value}") + elif value.lower() == "mc": + memory_value = 0 + print(f"Current memory value: {memory_value}") + elif value.lower() == "mrc": + print(f"Current memory value: {memory_value}") + return memory_value + + def switch_display_mode(self, mode, switch): + # Code to switch display mode + if mode.lower() == "hexadecimal": + print("Switched to hexadecimal display mode.") + return mode.lower() + elif mode.lower() == "binary": + print("Switched to binary display mode.") + return mode.lower() + elif mode.lower() == "decimal": + print("Switched to decimal display mode.") + return mode.lower() + elif mode.lower() == "octal": + print("Switched to octal display mode.") + return mode.lower() + else: + return switch.lower() # Return the current display mode if no switch command is given \ No newline at end of file diff --git a/main-app.py b/main-app.py index a7cc4e2..c0a5fb3 100644 --- a/main-app.py +++ b/main-app.py @@ -1,5 +1,5 @@ from calculator import Calculator - +from Display_functions import Display def getTwoNumbers(): a = float(input("first number? ")) @@ -7,26 +7,45 @@ def getTwoNumbers(): return a, b -def displayResult(x: float): - print(x, "\n") +def displayResult(x: float, mode: str): + if mode == "hexadecimal": + print(hex(int(x))) + elif mode == "binary": + print(bin(int(x))[2:]) + elif mode == "decimal": + print(x) + elif mode == "octal": + print(oct(int(x))) + else: + print(x, "\n") -def performCalcLoop(calc): +def performCalcLoop(calc, dis): + result = 0 + memory = 0 + switch = "decimal" # Default display mode while True: choice = input("Operation? ") + switch = dis.switch_display_mode(choice, switch) + memory = dis.store_memory(choice, memory, result) # Store the user's choice in memory if choice == 'q': break # user types q to quit calulator. elif choice == 'add': a, b = getTwoNumbers() - displayResult(calc.add(a, b)) + result = calc.add(a, b) + elif choice.lower() == "m+" or choice.lower() == "mc" or choice.lower() == "mrc" \ + or choice.lower() == "hexadecimal" or choice.lower() == "binary" or choice.lower() == "decimal" or choice.lower() == "octal": + continue else: print("That is not a valid input.") - + displayResult(result, switch) + print(switch) # main start def main(): calc = Calculator() - performCalcLoop(calc) + dis = Display() + performCalcLoop(calc, dis) print("Done Calculating.") From a536509a63a39d9aca6aadf19990dc88b6e51979 Mon Sep 17 00:00:00 2001 From: james Date: Sat, 28 Feb 2026 16:40:46 -0500 Subject: [PATCH 09/23] Added code for Base10 Logarithm, Natural Logarithm, and Inverse Natural Logarithm --- calctests.py | 12 ++++++++++++ calculator.py | 15 +++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/calctests.py b/calctests.py index 726912f..b654264 100644 --- a/calctests.py +++ b/calctests.py @@ -93,6 +93,18 @@ def log(self): c = Calculator() self.assertEqual(c.log(9), 2.1972245773362196) + def log10(self): + c = Calculator() + self.assertEqual(c.log10(9), 0.9542425094393249) + + def natlog(self): + c = Calculator() + self.assertEqual(c.natlog(9), 2.302585092994046) + + def in_natlog(self): + c = Calculator() + self.assertEqual(c.in_natlog(9), 0.43429448190325176) + if __name__ == '__main__': diff --git a/calculator.py b/calculator.py index effdd22..bceed65 100644 --- a/calculator.py +++ b/calculator.py @@ -61,5 +61,20 @@ def fac(self, x): def log(self, x): return math.log(x) + + def log10(self, x): + return math.log10(x) + + def log(self, x): + return math.log(x) + + def log(self, x): + return math.log(x) + + def natlog(self, x): + return math.log1p(x) + + def in_natlog(self, x): + return math.pow(log1p(x),-1) # add lots more methods to this calculator class. From 361522ec131b79cd1bdb3e9a56732ef2ec019aeb Mon Sep 17 00:00:00 2001 From: james Date: Sat, 28 Feb 2026 18:53:46 -0500 Subject: [PATCH 10/23] Test push with Paul --- calctests.py | 3 +++ calculator.py | 3 +++ 2 files changed, 6 insertions(+) diff --git a/calctests.py b/calctests.py index b654264..965f80e 100644 --- a/calctests.py +++ b/calctests.py @@ -105,6 +105,9 @@ def in_natlog(self): c = Calculator() self.assertEqual(c.in_natlog(9), 0.43429448190325176) + def infinity(self): + c = Calculator() + self.assertEqual(c.infinity(9),NaN) if __name__ == '__main__': diff --git a/calculator.py b/calculator.py index bceed65..53a7ebe 100644 --- a/calculator.py +++ b/calculator.py @@ -76,5 +76,8 @@ def natlog(self, x): def in_natlog(self, x): return math.pow(log1p(x),-1) + + def infinity(self, x): + return math.isinfinite(x) # add lots more methods to this calculator class. From 305dba46ed00ca88967a8eccb20b4763dfb93879 Mon Sep 17 00:00:00 2001 From: james Date: Sat, 28 Feb 2026 19:29:24 -0500 Subject: [PATCH 11/23] Add two required auxiliary functions: Infinity and Absolute Value --- calctests.py | 4 +++- calculator.py | 10 +++------- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/calctests.py b/calctests.py index 965f80e..91e1cbb 100644 --- a/calctests.py +++ b/calctests.py @@ -109,6 +109,8 @@ def infinity(self): c = Calculator() self.assertEqual(c.infinity(9),NaN) - + def abs_val(self): + c = Calculator() + self.assertEqual(c.abs_val(-9),9) if __name__ == '__main__': unittest.main() diff --git a/calculator.py b/calculator.py index 53a7ebe..8d1bb00 100644 --- a/calculator.py +++ b/calculator.py @@ -65,12 +65,6 @@ def log(self, x): def log10(self, x): return math.log10(x) - def log(self, x): - return math.log(x) - - def log(self, x): - return math.log(x) - def natlog(self, x): return math.log1p(x) @@ -79,5 +73,7 @@ def in_natlog(self, x): def infinity(self, x): return math.isinfinite(x) - + + def abs_val(self, x): + return math.fabs(x) # add lots more methods to this calculator class. From 6c78a57da238ef296d724bd4685f8fd357529aae Mon Sep 17 00:00:00 2001 From: david Date: Sun, 1 Mar 2026 11:17:38 -0500 Subject: [PATCH 12/23] Added terminal clean up and spacing. Added clear operation. --- Display_functions.py | 51 +++++++++++++++++++++++++++++++------ calculator.py | 2 +- main-app.py | 60 ++++++++++++++++++++++++++++++++++++-------- 3 files changed, 93 insertions(+), 20 deletions(-) diff --git a/Display_functions.py b/Display_functions.py index 030c330..a88b7b3 100644 --- a/Display_functions.py +++ b/Display_functions.py @@ -1,29 +1,64 @@ +import time + class Display: def store_memory(self, value, memory_value, current_result): # Code to store the value in memory if value.lower() == "m+": memory_value = current_result - print(f"Current memory value: {memory_value}") + print(f"\nCurrent memory value: {memory_value}", end="") elif value.lower() == "mc": memory_value = 0 - print(f"Current memory value: {memory_value}") + print(f"\nCurrent memory value: {memory_value}", end="") elif value.lower() == "mrc": - print(f"Current memory value: {memory_value}") + print(f"\nCurrent memory value: {memory_value}", end="") return memory_value def switch_display_mode(self, mode, switch): # Code to switch display mode if mode.lower() == "hexadecimal": - print("Switched to hexadecimal display mode.") + print("\nSwitched to hexadecimal display mode.", end="") return mode.lower() elif mode.lower() == "binary": - print("Switched to binary display mode.") + print("\nSwitched to binary display mode.", end="") return mode.lower() elif mode.lower() == "decimal": - print("Switched to decimal display mode.") + print("\nSwitched to decimal display mode.", end="") return mode.lower() elif mode.lower() == "octal": - print("Switched to octal display mode.") + print("\nSwitched to octal display mode.", end="") return mode.lower() else: - return switch.lower() # Return the current display mode if no switch command is given \ No newline at end of file + return switch.lower() # Return the current display mode if no switch command is given + + def self_destruct(self): + # Code to simulate self destruct sequence and exit the program + time.sleep(0.5) + print("Self destruct sequence initiated. \n Loading self_destruct.exe... \n initating count down sequence...") + time.sleep(1) + print("3...") + time.sleep(1) + print("2...") + time.sleep(1) + print("1...") + time.sleep(1) + print("\033[2J\033[H", end="") + print("\nBOOM! \n Error: self_destruct.exe has caused a fatal error \n Initiating backup restoration and kill command...") + + for i in range(3): + time.sleep(2) + print("\nLoading...", end="") + + print("\033[2J\033[H", end="") + print("\n\nBackup restoration complete. \n Kill command successful. \n Exiting program...") + print("Have a nice day") + exit() + + def display_clear(self, value): + # Code to clear the display + if value.lower() == "clear": + print("\033[2J\033[H", end="") # ANSI escape codes to clear the terminal screen + + def display_quitcancel(self): + # Code to display quit cancel message and return to previous state + print("\nReturning to previous state. Please wait...") + time.sleep(1) diff --git a/calculator.py b/calculator.py index 8d1bb00..0b60cbf 100644 --- a/calculator.py +++ b/calculator.py @@ -69,7 +69,7 @@ def natlog(self, x): return math.log1p(x) def in_natlog(self, x): - return math.pow(log1p(x),-1) + return math.pow(math.log1p(x),-1) def infinity(self, x): return math.isinfinite(x) diff --git a/main-app.py b/main-app.py index c0a5fb3..e0e9d72 100644 --- a/main-app.py +++ b/main-app.py @@ -2,20 +2,23 @@ from Display_functions import Display def getTwoNumbers(): - a = float(input("first number? ")) + a = float(input("\nfirst number? ")) b = float(input("second number? ")) return a, b +def getOneNumber(): + a = float(input("\nnumber? ")) + return a def displayResult(x: float, mode: str): if mode == "hexadecimal": - print(hex(int(x))) + print(hex(int(x))[2:], end="") # [2:] to remove the '0x' prefix from the hexadecimal representation elif mode == "binary": - print(bin(int(x))[2:]) + print(bin(int(x))[2:], end="") # [2:] to remove the '0b' prefix from the binary representation elif mode == "decimal": - print(x) + print(x, end="") elif mode == "octal": - print(oct(int(x))) + print(oct(int(x))[2:], end="") # [2:] to remove the '0o' prefix from the octal representation else: print(x, "\n") @@ -24,29 +27,64 @@ def performCalcLoop(calc, dis): result = 0 memory = 0 switch = "decimal" # Default display mode + print("\nWelcome to the Scientific Calculator!", end="") + while True: - choice = input("Operation? ") - switch = dis.switch_display_mode(choice, switch) + print("\n") + choice = input("Type help for a list of operations or enter an operation \noperation: ") + + switch = dis.switch_display_mode(choice, switch) # Switch display mode if the user input is a display mode command memory = dis.store_memory(choice, memory, result) # Store the user's choice in memory + + # Display operations and quit command if choice == 'q': - break # user types q to quit calulator. + while True: + final_choice = input("\nAre you sure you want to quit? (y/n) ") + if final_choice.lower() == 'y': + return # user types q to quit calculator. + elif final_choice.lower() == 'n': + dis.display_quitcancel() # user cancels quit command, return to previous state. + break # user chooses not to quit, continue with calculator. + else: + print("\nCommand not recognized. Rerunning user_interface.exe, please try again.") + + elif choice == 'help': + print("\nAvailable operations: add, sub, mult, div, sqr, root2, exp, inv, neg, sin, cos, tan, isin, icos, itan, deg, rad, fac") + print("Memory operations: M+ (store current result in memory), MC (clear memory), MRC (recall memory)") + print("Display mode operations: hexadecimal, binary, decimal, octal") + print("Other operations: clear (clears the display), q (quit the calculator)") + continue + elif choice == 'clear': + dis.display_clear(choice) + continue + + # Implementing calculator operations elif choice == 'add': a, b = getTwoNumbers() result = calc.add(a, b) + + # Passes or invalid imput elif choice.lower() == "m+" or choice.lower() == "mc" or choice.lower() == "mrc" \ or choice.lower() == "hexadecimal" or choice.lower() == "binary" or choice.lower() == "decimal" or choice.lower() == "octal": continue else: - print("That is not a valid input.") + print("\nThat is not a valid input. Please try again.", end="") + continue + + print(f"\nCurrent decimal memory value: {memory}") + print(f"Current display mode: {switch}\n") + print("Result: ", end="") displayResult(result, switch) - print(switch) + # main start def main(): calc = Calculator() dis = Display() + dis.display_clear("clear") performCalcLoop(calc, dis) - print("Done Calculating.") + print("\nDone Calculating.\n") + dis.self_destruct() if __name__ == '__main__': From 934b7b5f622f66ea10a45015dcc64f04698048e3 Mon Sep 17 00:00:00 2001 From: james Date: Sun, 1 Mar 2026 12:06:11 -0500 Subject: [PATCH 13/23] Added math operator code to main-app.py --- main-app.py | 92 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) diff --git a/main-app.py b/main-app.py index e0e9d72..de694fd 100644 --- a/main-app.py +++ b/main-app.py @@ -63,6 +63,98 @@ def performCalcLoop(calc, dis): a, b = getTwoNumbers() result = calc.add(a, b) + elif choice == 'sub': + a, b = getTwoNumbers() + result = calc.sub(a, b) + + elif choice == 'mult': + a, b = getTwoNumbers() + result = calc.mult(a, b) + + elif choice == 'div': + a, b = getTwoNumbers() + result = calc.div(a, b) + + elif choice == 'sqr': + a = getOneNumber() + result = calc.sqr(a) + + elif choice == 'root2': + a = getOneNumber() + result = calc.root2(a) + + elif choice == 'exp': + a, b = getTwoNumbers() + result = calc.exp(a, b) + + elif choice == 'inv': + a = getOneNumber() + result = calc.inv(a) + + elif choice == 'neg': + a = getOneNumber() + result = calc.neg(a) + + elif choice == 'sin': + a = getOneNumber() + result = calc.sin(a) + + elif choice == 'cos': + a = getOneNumber() + result = calc.cos(a) + + elif choice == 'tan': + a = getOneNumber() + result = calc.tan(a) + + elif choice == 'isin': + a = getOneNumber() + result = calc.isin(a) + + elif choice == 'icos': + a = getOneNumber() + result = calc.icos(a) + + elif choice == 'itan': + a = getOneNumber() + result = calc.itan(a) + + elif choice == 'deg': + a = getOneNumber() + result = calc.deg(a) + + elif choice == 'rad': + a = getOneNumber() + result = calc.rad(a) + + elif choice == 'fac': + a = getOneNumber() + result = calc.fac(a) + + elif choice == 'log': + a = getOneNumber() + result = calc.log(a) + + elif choice == 'log10': + a = getOneNumber() + result = calc.log10(a) + + elif choice == 'natlog': + a = getOneNumber() + result = calc.natlog(a) + + elif choice == 'in_natlog': + a = getOneNumber() + result = calc.in_natlog(a) + + elif choice == 'infinity': + a = getOneNumber() + result = calc.infinity(a) + + elif choice == 'abs_val': + a = getOneNumber() + result = calc.abs_val(a) + # Passes or invalid imput elif choice.lower() == "m+" or choice.lower() == "mc" or choice.lower() == "mrc" \ or choice.lower() == "hexadecimal" or choice.lower() == "binary" or choice.lower() == "decimal" or choice.lower() == "octal": From 9266c27a66d79e8bba9c3e839240e97814267874 Mon Sep 17 00:00:00 2001 From: david Date: Sun, 1 Mar 2026 12:47:17 -0500 Subject: [PATCH 14/23] Added operation format look for equation --- main-app.py | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 52 insertions(+), 2 deletions(-) diff --git a/main-app.py b/main-app.py index de694fd..4af79ec 100644 --- a/main-app.py +++ b/main-app.py @@ -25,6 +25,7 @@ def displayResult(x: float, mode: str): def performCalcLoop(calc, dis): result = 0 + result_format = "" memory = 0 switch = "decimal" # Default display mode print("\nWelcome to the Scientific Calculator!", end="") @@ -49,7 +50,7 @@ def performCalcLoop(calc, dis): print("\nCommand not recognized. Rerunning user_interface.exe, please try again.") elif choice == 'help': - print("\nAvailable operations: add, sub, mult, div, sqr, root2, exp, inv, neg, sin, cos, tan, isin, icos, itan, deg, rad, fac") + print("\nAvailable operations: add, sub, mult, div, sqr, root2, exp, inv, neg, sin, cos, tan, isin, icos, itan, deg, rad, fac, log, log10, natlog, in_natlog, infinity, abs_val") print("Memory operations: M+ (store current result in memory), MC (clear memory), MRC (recall memory)") print("Display mode operations: hexadecimal, binary, decimal, octal") print("Other operations: clear (clears the display), q (quit the calculator)") @@ -60,100 +61,148 @@ def performCalcLoop(calc, dis): # Implementing calculator operations elif choice == 'add': + print("\nFormat: [number1] + [number2]") a, b = getTwoNumbers() result = calc.add(a, b) + result_format = f"{a} + {b} = {result}" elif choice == 'sub': + print("\nFormat: [number1] - [number2]") a, b = getTwoNumbers() result = calc.sub(a, b) + result_format = f"{a} - {b} = {result}" elif choice == 'mult': + print("\nFormat: [number1] * [number2]") a, b = getTwoNumbers() result = calc.mult(a, b) + result_format = f"{a} * {b} = {result}" elif choice == 'div': + print("\nFormat: [number1] / [number2]") a, b = getTwoNumbers() result = calc.div(a, b) + result_format = f"{a} / {b} = {result}" elif choice == 'sqr': + print("\nFormat: [number] ^ 2") a = getOneNumber() result = calc.sqr(a) + result_format = f"{a} ^ 2 = {result}" elif choice == 'root2': + print("\nFormat: sqrt([number])") a = getOneNumber() result = calc.root2(a) + result_format = f"sqrt({a}) = {result}" elif choice == 'exp': + print("\nFormat: [number1] ^ [number2]") a, b = getTwoNumbers() result = calc.exp(a, b) + result_format = f"{a} ^ {b} = {result}" elif choice == 'inv': + print("\nFormat: 1 / [number]") a = getOneNumber() result = calc.inv(a) + result_format = f"1 / {a} = {result}" elif choice == 'neg': + print("\nFormat: -[number]") a = getOneNumber() result = calc.neg(a) + result_format = f"-{a} = {result}" elif choice == 'sin': + print("\nFormat: sin([number])") a = getOneNumber() result = calc.sin(a) + result_format = f"sin({a}) = {result}" elif choice == 'cos': + print("\nFormat: cos([number])") a = getOneNumber() result = calc.cos(a) + result_format = f"cos({a}) = {result}" elif choice == 'tan': + print("\nFormat: tan([number])") a = getOneNumber() result = calc.tan(a) + result_format = f"tan({a}) = {result}" elif choice == 'isin': + print("\nFormat: arcsin([number])") a = getOneNumber() result = calc.isin(a) + result_format = f"arcsin({a}) = {result}" elif choice == 'icos': + print("\nFormat: arccos([number])") a = getOneNumber() result = calc.icos(a) + result_format = f"arccos({a}) = {result}" elif choice == 'itan': + print("\nFormat: arctan([number])") a = getOneNumber() result = calc.itan(a) + result_format = f"arctan({a}) = {result}" elif choice == 'deg': + print("\nFormat: deg([number])") a = getOneNumber() result = calc.deg(a) + result_format = f"deg({a}) = {result}" elif choice == 'rad': + print("\nFormat: rad([number])") a = getOneNumber() result = calc.rad(a) + result_format = f"rad({a}) = {result}" elif choice == 'fac': + print("\nFormat: [number]!") a = getOneNumber() result = calc.fac(a) + result_format = f"{a}! = {result}" elif choice == 'log': + print("\nFormat: log([number])") a = getOneNumber() result = calc.log(a) + result_format = f"log({a}) = {result}" elif choice == 'log10': + print("\nFormat: log10([number])") a = getOneNumber() result = calc.log10(a) + result_format = f"log10({a}) = {result}" elif choice == 'natlog': + print("\nFormat: ln([number])") a = getOneNumber() result = calc.natlog(a) + result_format = f"ln({a}) = {result}" elif choice == 'in_natlog': + print("\nFormat: in_ln([number])") a = getOneNumber() result = calc.in_natlog(a) + result_format = f"in_ln({a}) = {result}" elif choice == 'infinity': + print("\nFormat: infinity([number])") a = getOneNumber() result = calc.infinity(a) + result_format = f"infinity({a}) = {result}" elif choice == 'abs_val': + print("\nFormat: abs([number])") a = getOneNumber() result = calc.abs_val(a) + result_format = f"abs({a}) = {result}" # Passes or invalid imput elif choice.lower() == "m+" or choice.lower() == "mc" or choice.lower() == "mrc" \ @@ -165,7 +214,8 @@ def performCalcLoop(calc, dis): print(f"\nCurrent decimal memory value: {memory}") print(f"Current display mode: {switch}\n") - print("Result: ", end="") + print(f"{result_format}") + print("Displaying result in current display mode: ", end="") displayResult(result, switch) From 55f4af34f8a86c38604193bd29e51b46c9493d92 Mon Sep 17 00:00:00 2001 From: james Date: Sun, 1 Mar 2026 12:51:19 -0500 Subject: [PATCH 15/23] Corrected method for Infinity feature. --- calculator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/calculator.py b/calculator.py index 0b60cbf..412421b 100644 --- a/calculator.py +++ b/calculator.py @@ -72,7 +72,7 @@ def in_natlog(self, x): return math.pow(math.log1p(x),-1) def infinity(self, x): - return math.isinfinite(x) + return math.isfinite(x) def abs_val(self, x): return math.fabs(x) From 9b29ef45cdb8add27ef0169db9c2efa806fd6d4a Mon Sep 17 00:00:00 2001 From: nate Date: Sun, 1 Mar 2026 13:39:33 -0500 Subject: [PATCH 16/23] Added trigonemtric functions to switch between degrees and radian --- Display_functions.py | 41 +++++++++++++++++++++++++++++++++++++++++ main-app.py | 23 ++++++++++++++++++----- 2 files changed, 59 insertions(+), 5 deletions(-) diff --git a/Display_functions.py b/Display_functions.py index a88b7b3..41049e4 100644 --- a/Display_functions.py +++ b/Display_functions.py @@ -12,6 +12,28 @@ def store_memory(self, value, memory_value, current_result): elif value.lower() == "mrc": print(f"\nCurrent memory value: {memory_value}", end="") return memory_value + + def trig_display(self, mode, switch): + # Code to display trigonometric results in the correct mode + if mode.lower() == "deg": + print("\nDisplaying result in degree mode.", end="") + return mode.lower() + elif mode.lower() == "rad": + print("\nDisplaying result in radian mode.", end="") + return mode.lower() + else: + return switch.lower() # Return the current display mode if no switch command is given + + def auto_trig_display(self, switch): + # Code to automatically switch trigonometric display mode based on the current mode + if switch == "deg": + print("\nDisplaying result in radian mode.", end="") + return "rad" + elif switch == "rad": + print("\nDisplaying result in degree mode.", end="") + return "deg" + else: + return switch # Return the current display mode if no auto switch is defined def switch_display_mode(self, mode, switch): # Code to switch display mode @@ -30,6 +52,25 @@ def switch_display_mode(self, mode, switch): else: return switch.lower() # Return the current display mode if no switch command is given + def auto_display_mode(self, switch): + # Code to automatically switch display mode based on the result + if switch == "hexadecimal": + print("\nDisplaying result in binary display mode.", end="") + return "binary" + elif switch == "binary": + print("\nDisplaying result in octal display mode.", end="") + return "octal" + elif switch == "octal": + print("\nDisplaying result in decimal display mode.", end="") + return "decimal" + elif switch == "decimal": + print("\nDisplaying result in hexadecimal display mode.", end="") + return "hexadecimal" + + else: + return switch # Return the current display mode if no auto switch is defined + + def self_destruct(self): # Code to simulate self destruct sequence and exit the program time.sleep(0.5) diff --git a/main-app.py b/main-app.py index 4af79ec..a08e9fc 100644 --- a/main-app.py +++ b/main-app.py @@ -10,6 +10,16 @@ def getOneNumber(): a = float(input("\nnumber? ")) return a +def trig_display(mode, switch): + if mode == "deg": + print("\nDisplaying result in degree mode.", end="") + return mode + elif mode == "rad": + print("\nDisplaying result in radian mode.", end="") + return mode + else: + return switch # Return the current display mode if no switch command is given + def displayResult(x: float, mode: str): if mode == "hexadecimal": print(hex(int(x))[2:], end="") # [2:] to remove the '0x' prefix from the hexadecimal representation @@ -50,14 +60,17 @@ def performCalcLoop(calc, dis): print("\nCommand not recognized. Rerunning user_interface.exe, please try again.") elif choice == 'help': - print("\nAvailable operations: add, sub, mult, div, sqr, root2, exp, inv, neg, sin, cos, tan, isin, icos, itan, deg, rad, fac, log, log10, natlog, in_natlog, infinity, abs_val") + print("\nAvailable operations: add, sub, mult, div, sqr, root2, exp, inv, neg, sin, cos, tan, isin, icos, itan, deg, rad, fac, log, log10, natlog, in_natlog, finite, abs_val") print("Memory operations: M+ (store current result in memory), MC (clear memory), MRC (recall memory)") - print("Display mode operations: hexadecimal, binary, decimal, octal") + print("Display mode operations: hexadecimal, binary, decimal, octal, switch (automatically switch display mode), trig (automatically switch trigonometric display mode), deg (switch to degree mode), rad (switch to radian mode)") print("Other operations: clear (clears the display), q (quit the calculator)") continue elif choice == 'clear': dis.display_clear(choice) continue + elif choice.lower() == "switch": + switch = dis.auto_display_mode(switch) + continue # Implementing calculator operations elif choice == 'add': @@ -192,11 +205,11 @@ def performCalcLoop(calc, dis): result = calc.in_natlog(a) result_format = f"in_ln({a}) = {result}" - elif choice == 'infinity': - print("\nFormat: infinity([number])") + elif choice == 'finite': + print("\nFormat: finite([number])") a = getOneNumber() result = calc.infinity(a) - result_format = f"infinity({a}) = {result}" + result_format = f"is finite({a}) = {result}" elif choice == 'abs_val': print("\nFormat: abs([number])") From 9a8892246cadca78f1f15bebdab18a650ad9b816 Mon Sep 17 00:00:00 2001 From: david Date: Sun, 1 Mar 2026 14:45:21 -0500 Subject: [PATCH 17/23] Added trig displace switching --- main-app.py | 51 +++++++++++++++++++++++++++++++++++---------------- 1 file changed, 35 insertions(+), 16 deletions(-) diff --git a/main-app.py b/main-app.py index a08e9fc..ba46d4f 100644 --- a/main-app.py +++ b/main-app.py @@ -9,16 +9,6 @@ def getTwoNumbers(): def getOneNumber(): a = float(input("\nnumber? ")) return a - -def trig_display(mode, switch): - if mode == "deg": - print("\nDisplaying result in degree mode.", end="") - return mode - elif mode == "rad": - print("\nDisplaying result in radian mode.", end="") - return mode - else: - return switch # Return the current display mode if no switch command is given def displayResult(x: float, mode: str): if mode == "hexadecimal": @@ -32,12 +22,23 @@ def displayResult(x: float, mode: str): else: print(x, "\n") +def displayTrigResult(x: float, mode: str): + if mode == "degree": + print(f"{Calculator.deg(x,x)} degrees", end="") + return Calculator.deg(x,x) + elif mode == "radian": + print(f"{x} radians", end="") + return x + else: + print(x, "\n") + def performCalcLoop(calc, dis): result = 0 result_format = "" memory = 0 switch = "decimal" # Default display mode + trig_switch = "degree" # Default trigonometric display mode print("\nWelcome to the Scientific Calculator!", end="") while True: @@ -46,7 +47,8 @@ def performCalcLoop(calc, dis): switch = dis.switch_display_mode(choice, switch) # Switch display mode if the user input is a display mode command memory = dis.store_memory(choice, memory, result) # Store the user's choice in memory - + trig_switch = dis.trig_display(choice, trig_switch) # Switch trigonometric display mode if the user input is a trig display mode command + # Display operations and quit command if choice == 'q': while True: @@ -62,15 +64,19 @@ def performCalcLoop(calc, dis): elif choice == 'help': print("\nAvailable operations: add, sub, mult, div, sqr, root2, exp, inv, neg, sin, cos, tan, isin, icos, itan, deg, rad, fac, log, log10, natlog, in_natlog, finite, abs_val") print("Memory operations: M+ (store current result in memory), MC (clear memory), MRC (recall memory)") - print("Display mode operations: hexadecimal, binary, decimal, octal, switch (automatically switch display mode), trig (automatically switch trigonometric display mode), deg (switch to degree mode), rad (switch to radian mode)") + print("Display mode operations: hexadecimal, binary, decimal, octal, switch (automatically switch display mode), trig (automatically switch trigonometric display mode), degree (switch to degree mode), radian (switch to radian mode)") print("Other operations: clear (clears the display), q (quit the calculator)") continue elif choice == 'clear': dis.display_clear(choice) continue + elif choice.lower() == "switch": switch = dis.auto_display_mode(switch) continue + elif choice.lower() == "trig": + trig_switch = dis.auto_trig_display(trig_switch) + continue # Implementing calculator operations elif choice == 'add': @@ -128,36 +134,43 @@ def performCalcLoop(calc, dis): result_format = f"-{a} = {result}" elif choice == 'sin': + print(f"\nCurrent trigonometric input mode: {trig_switch}") print("\nFormat: sin([number])") a = getOneNumber() + a = calc.rad(a) if trig_switch == "degree" else a # Convert input to radians if in degree mode result = calc.sin(a) result_format = f"sin({a}) = {result}" elif choice == 'cos': + print(f"\nCurrent trigonometric input mode: {trig_switch}") print("\nFormat: cos([number])") a = getOneNumber() result = calc.cos(a) result_format = f"cos({a}) = {result}" elif choice == 'tan': + print(f"\nCurrent trigonometric input mode: {trig_switch}") print("\nFormat: tan([number])") a = getOneNumber() result = calc.tan(a) result_format = f"tan({a}) = {result}" elif choice == 'isin': + print(f"\nCurrent trigonometric input mode: {trig_switch}") print("\nFormat: arcsin([number])") a = getOneNumber() result = calc.isin(a) result_format = f"arcsin({a}) = {result}" elif choice == 'icos': + print(f"\nCurrent trigonometric input mode: {trig_switch}") print("\nFormat: arccos([number])") a = getOneNumber() result = calc.icos(a) result_format = f"arccos({a}) = {result}" elif choice == 'itan': + print(f"\nCurrent trigonometric input mode: {trig_switch}") print("\nFormat: arctan([number])") a = getOneNumber() result = calc.itan(a) @@ -219,7 +232,8 @@ def performCalcLoop(calc, dis): # Passes or invalid imput elif choice.lower() == "m+" or choice.lower() == "mc" or choice.lower() == "mrc" \ - or choice.lower() == "hexadecimal" or choice.lower() == "binary" or choice.lower() == "decimal" or choice.lower() == "octal": + or choice.lower() == "hexadecimal" or choice.lower() == "binary" or choice.lower() == "decimal" or choice.lower() == "octal" \ + or choice.lower() == "degree" or choice.lower() == "radian" or choice.lower() == "switch" or choice.lower() == "trig": continue else: print("\nThat is not a valid input. Please try again.", end="") @@ -227,9 +241,14 @@ def performCalcLoop(calc, dis): print(f"\nCurrent decimal memory value: {memory}") print(f"Current display mode: {switch}\n") - print(f"{result_format}") - print("Displaying result in current display mode: ", end="") - displayResult(result, switch) + if choice in ['sin', 'cos', 'tan', 'isin', 'icos', 'itan']: + print(f"Current trigonometric display mode: {trig_switch}\n") + print(f"{result_format}") + displayTrigResult(result, trig_switch) + else: + print(f"{result_format}") + print("Displaying result in current display mode: ", end="") + displayResult(result, switch) # main start From edf4fbe04f9be58e53c3c45924e3713f1ea73c0d Mon Sep 17 00:00:00 2001 From: nate Date: Sun, 1 Mar 2026 15:10:43 -0500 Subject: [PATCH 18/23] Committed Memory history additions to recall more than a single calculated value --- Display_functions.py | 24 ++++++++++++++++++------ main-app.py | 8 ++++++-- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/Display_functions.py b/Display_functions.py index 41049e4..7c9eedc 100644 --- a/Display_functions.py +++ b/Display_functions.py @@ -13,12 +13,24 @@ def store_memory(self, value, memory_value, current_result): print(f"\nCurrent memory value: {memory_value}", end="") return memory_value + def memory_history(self, value, history_value): + history_value.append(value) + + def display_history(self, value, history_value): + if value.lower() == "h": + print("\nMemory history:", end="") + print(history_value) + elif value.lower() == "hc": + history_value.clear() + print("\nMemory history cleared.") + + def trig_display(self, mode, switch): # Code to display trigonometric results in the correct mode - if mode.lower() == "deg": + if mode.lower() == "degree": print("\nDisplaying result in degree mode.", end="") return mode.lower() - elif mode.lower() == "rad": + elif mode.lower() == "radian": print("\nDisplaying result in radian mode.", end="") return mode.lower() else: @@ -26,12 +38,12 @@ def trig_display(self, mode, switch): def auto_trig_display(self, switch): # Code to automatically switch trigonometric display mode based on the current mode - if switch == "deg": + if switch == "degree": print("\nDisplaying result in radian mode.", end="") - return "rad" - elif switch == "rad": + return "radian" + elif switch == "radian": print("\nDisplaying result in degree mode.", end="") - return "deg" + return "degree" else: return switch # Return the current display mode if no auto switch is defined diff --git a/main-app.py b/main-app.py index ba46d4f..2398192 100644 --- a/main-app.py +++ b/main-app.py @@ -37,6 +37,7 @@ def performCalcLoop(calc, dis): result = 0 result_format = "" memory = 0 + result_history = [] switch = "decimal" # Default display mode trig_switch = "degree" # Default trigonometric display mode print("\nWelcome to the Scientific Calculator!", end="") @@ -48,6 +49,7 @@ def performCalcLoop(calc, dis): switch = dis.switch_display_mode(choice, switch) # Switch display mode if the user input is a display mode command memory = dis.store_memory(choice, memory, result) # Store the user's choice in memory trig_switch = dis.trig_display(choice, trig_switch) # Switch trigonometric display mode if the user input is a trig display mode command + dis.display_history(choice, result_history) # Display operations and quit command if choice == 'q': @@ -233,7 +235,8 @@ def performCalcLoop(calc, dis): # Passes or invalid imput elif choice.lower() == "m+" or choice.lower() == "mc" or choice.lower() == "mrc" \ or choice.lower() == "hexadecimal" or choice.lower() == "binary" or choice.lower() == "decimal" or choice.lower() == "octal" \ - or choice.lower() == "degree" or choice.lower() == "radian" or choice.lower() == "switch" or choice.lower() == "trig": + or choice.lower() == "degree" or choice.lower() == "radian" or choice.lower() == "switch" or choice.lower() == "trig" \ + or choice.lower() == "h" or choice.lower() == "hc": continue else: print("\nThat is not a valid input. Please try again.", end="") @@ -245,11 +248,12 @@ def performCalcLoop(calc, dis): print(f"Current trigonometric display mode: {trig_switch}\n") print(f"{result_format}") displayTrigResult(result, trig_switch) + memory_history = dis.memory_history(result, result_history) else: print(f"{result_format}") print("Displaying result in current display mode: ", end="") displayResult(result, switch) - + memory_history = dis.memory_history(result, result_history) # main start def main(): From c93dd94363d381101263be63e97cb2646d0a2612 Mon Sep 17 00:00:00 2001 From: david Date: Sun, 1 Mar 2026 16:21:36 -0500 Subject: [PATCH 19/23] Add history recall method and divide by zero error continue --- Display_functions.py | 11 +++- calculator.py | 8 ++- main-app.py | 118 ++++++++++++++++++++++++++++++++----------- 3 files changed, 103 insertions(+), 34 deletions(-) diff --git a/Display_functions.py b/Display_functions.py index 7c9eedc..87e2fc9 100644 --- a/Display_functions.py +++ b/Display_functions.py @@ -19,10 +19,17 @@ def memory_history(self, value, history_value): def display_history(self, value, history_value): if value.lower() == "h": print("\nMemory history:", end="") - print(history_value) + print(history_value, end="") elif value.lower() == "hc": history_value.clear() - print("\nMemory history cleared.") + print("\nMemory history cleared.", end="") + + def history_call(self, value, history_value): + if value < 0 or value >= len(history_value): + print("\nInvalid history index. Please try again.") + return None + else: + return history_value[value] def trig_display(self, mode, switch): diff --git a/calculator.py b/calculator.py index 412421b..5879bae 100644 --- a/calculator.py +++ b/calculator.py @@ -9,13 +9,17 @@ def add(self, x, y): return x + y def sub(self, x, y): - return x -y + return x - y def mult(self, x, y): return x * y def div(self, x, y): - return x / y + if y == 0: + print("\nError: Division by zero is not allowed.") + return None + else: + return x / y def sqr(self, x): return x * x diff --git a/main-app.py b/main-app.py index 2398192..9fa26a4 100644 --- a/main-app.py +++ b/main-app.py @@ -1,13 +1,64 @@ from calculator import Calculator from Display_functions import Display -def getTwoNumbers(): - a = float(input("\nfirst number? ")) - b = float(input("second number? ")) +def getTwoNumbers(result_history): + while True: + a = input("\nIf wish to use history input 'h' else input number \nfirst number? ") + if a == "h": + while True: + Display.display_history(None, "h", result_history) + a = input("\nEnter the index of the history value you wish to use or 'e' to return to number input \nIndex: ") + if a == "e": + break + a = int(a) + a = Display.history_call(None, a, result_history) + if a is not None: + break + if a == "e": + continue + else: + print(f"\nUsing history value: {a}") + break + else: + a = float(a) + break + while True: + b = input("\nIf wish to use history input 'h' else input number \nsecond number? ") + if b == "h": + Display.display_history(None, "h", result_history) + while True: + b = input("\nEnter the index of the history value you wish to use or 'e' to return to number input \nIndex: ") + if b == "e": + break + b = int(b) + b = Display.history_call(None, b, result_history) + if b is not None: + break + print(f"\nUsing history value: {b}") + break + else: + b = float(b) + break return a, b -def getOneNumber(): - a = float(input("\nnumber? ")) +def getOneNumber(result_history): + while True: + a = input("\nIf wish to use history input 'h' else input number \nnumber? ") + if a == "h": + while True: + Display.display_history(None, "h", result_history) + a = input("\nEnter the index of the history value you wish to use or 'e' to return to number input \nIndex: ") + if a == "e": + break + a = int(a) + a = Display.history_call(None, a, result_history) + if a is not None: + break + print(f"\nUsing history value: {a}") + break + else: + a = float(a) + break return a def displayResult(x: float, mode: str): @@ -66,6 +117,7 @@ def performCalcLoop(calc, dis): elif choice == 'help': print("\nAvailable operations: add, sub, mult, div, sqr, root2, exp, inv, neg, sin, cos, tan, isin, icos, itan, deg, rad, fac, log, log10, natlog, in_natlog, finite, abs_val") print("Memory operations: M+ (store current result in memory), MC (clear memory), MRC (recall memory)") + print("Memory history operations: H (display memory history), HC (clear memory history)") print("Display mode operations: hexadecimal, binary, decimal, octal, switch (automatically switch display mode), trig (automatically switch trigonometric display mode), degree (switch to degree mode), radian (switch to radian mode)") print("Other operations: clear (clears the display), q (quit the calculator)") continue @@ -83,62 +135,66 @@ def performCalcLoop(calc, dis): # Implementing calculator operations elif choice == 'add': print("\nFormat: [number1] + [number2]") - a, b = getTwoNumbers() + a, b = getTwoNumbers(result_history) result = calc.add(a, b) result_format = f"{a} + {b} = {result}" elif choice == 'sub': print("\nFormat: [number1] - [number2]") - a, b = getTwoNumbers() + a, b = getTwoNumbers(result_history) result = calc.sub(a, b) result_format = f"{a} - {b} = {result}" elif choice == 'mult': print("\nFormat: [number1] * [number2]") - a, b = getTwoNumbers() + a, b = getTwoNumbers(result_history) result = calc.mult(a, b) result_format = f"{a} * {b} = {result}" elif choice == 'div': print("\nFormat: [number1] / [number2]") - a, b = getTwoNumbers() + a, b = getTwoNumbers(result_history) result = calc.div(a, b) - result_format = f"{a} / {b} = {result}" + if b == 0: + result_format = f"{a} / {b} = Error (division by zero is not allowed)" + continue + else: + result_format = f"{a} / {b} = {result}" elif choice == 'sqr': print("\nFormat: [number] ^ 2") - a = getOneNumber() + a = getOneNumber(result_history) result = calc.sqr(a) result_format = f"{a} ^ 2 = {result}" elif choice == 'root2': print("\nFormat: sqrt([number])") - a = getOneNumber() + a = getOneNumber(result_history) result = calc.root2(a) result_format = f"sqrt({a}) = {result}" elif choice == 'exp': print("\nFormat: [number1] ^ [number2]") - a, b = getTwoNumbers() + a, b = getTwoNumbers(result_history) result = calc.exp(a, b) result_format = f"{a} ^ {b} = {result}" elif choice == 'inv': print("\nFormat: 1 / [number]") - a = getOneNumber() + a = getOneNumber(result_history) result = calc.inv(a) result_format = f"1 / {a} = {result}" elif choice == 'neg': print("\nFormat: -[number]") - a = getOneNumber() + a = getOneNumber(result_history) result = calc.neg(a) result_format = f"-{a} = {result}" elif choice == 'sin': print(f"\nCurrent trigonometric input mode: {trig_switch}") print("\nFormat: sin([number])") - a = getOneNumber() + a = getOneNumber(result_history) a = calc.rad(a) if trig_switch == "degree" else a # Convert input to radians if in degree mode result = calc.sin(a) result_format = f"sin({a}) = {result}" @@ -146,89 +202,89 @@ def performCalcLoop(calc, dis): elif choice == 'cos': print(f"\nCurrent trigonometric input mode: {trig_switch}") print("\nFormat: cos([number])") - a = getOneNumber() + a = getOneNumber(result_history) result = calc.cos(a) result_format = f"cos({a}) = {result}" elif choice == 'tan': print(f"\nCurrent trigonometric input mode: {trig_switch}") print("\nFormat: tan([number])") - a = getOneNumber() + a = getOneNumber(result_history) result = calc.tan(a) result_format = f"tan({a}) = {result}" elif choice == 'isin': print(f"\nCurrent trigonometric input mode: {trig_switch}") print("\nFormat: arcsin([number])") - a = getOneNumber() + a = getOneNumber(result_history) result = calc.isin(a) result_format = f"arcsin({a}) = {result}" elif choice == 'icos': print(f"\nCurrent trigonometric input mode: {trig_switch}") print("\nFormat: arccos([number])") - a = getOneNumber() + a = getOneNumber(result_history) result = calc.icos(a) result_format = f"arccos({a}) = {result}" elif choice == 'itan': print(f"\nCurrent trigonometric input mode: {trig_switch}") print("\nFormat: arctan([number])") - a = getOneNumber() + a = getOneNumber(result_history) result = calc.itan(a) result_format = f"arctan({a}) = {result}" elif choice == 'deg': print("\nFormat: deg([number])") - a = getOneNumber() + a = getOneNumber(result_history) result = calc.deg(a) result_format = f"deg({a}) = {result}" elif choice == 'rad': print("\nFormat: rad([number])") - a = getOneNumber() + a = getOneNumber(result_history) result = calc.rad(a) result_format = f"rad({a}) = {result}" elif choice == 'fac': print("\nFormat: [number]!") - a = getOneNumber() + a = getOneNumber(result_history) result = calc.fac(a) result_format = f"{a}! = {result}" elif choice == 'log': print("\nFormat: log([number])") - a = getOneNumber() + a = getOneNumber(result_history) result = calc.log(a) result_format = f"log({a}) = {result}" elif choice == 'log10': print("\nFormat: log10([number])") - a = getOneNumber() + a = getOneNumber(result_history) result = calc.log10(a) result_format = f"log10({a}) = {result}" elif choice == 'natlog': print("\nFormat: ln([number])") - a = getOneNumber() + a = getOneNumber(result_history) result = calc.natlog(a) result_format = f"ln({a}) = {result}" elif choice == 'in_natlog': print("\nFormat: in_ln([number])") - a = getOneNumber() + a = getOneNumber(result_history) result = calc.in_natlog(a) result_format = f"in_ln({a}) = {result}" elif choice == 'finite': print("\nFormat: finite([number])") - a = getOneNumber() + a = getOneNumber(result_history) result = calc.infinity(a) result_format = f"is finite({a}) = {result}" elif choice == 'abs_val': print("\nFormat: abs([number])") - a = getOneNumber() + a = getOneNumber(result_history) result = calc.abs_val(a) result_format = f"abs({a}) = {result}" @@ -248,6 +304,8 @@ def performCalcLoop(calc, dis): print(f"Current trigonometric display mode: {trig_switch}\n") print(f"{result_format}") displayTrigResult(result, trig_switch) + if trig_switch == "degree": + result = calc.deg(result) memory_history = dis.memory_history(result, result_history) else: print(f"{result_format}") From e04ecd2eb91caf9fd9afcd150783f4880675e3aa Mon Sep 17 00:00:00 2001 From: nate Date: Sun, 1 Mar 2026 16:42:09 -0500 Subject: [PATCH 20/23] Changed wording of Division error, it's not that dividing by 0 isn't allowed. It just doesn't bring a proper result --- calculator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/calculator.py b/calculator.py index 5879bae..531fd80 100644 --- a/calculator.py +++ b/calculator.py @@ -16,7 +16,7 @@ def mult(self, x, y): def div(self, x, y): if y == 0: - print("\nError: Division by zero is not allowed.") + print("\nError: Division by zero is not defined.") return None else: return x / y From e00312c61b6d1614dacc93f907dc6ad204bd54fa Mon Sep 17 00:00:00 2001 From: david Date: Sun, 1 Mar 2026 17:49:28 -0500 Subject: [PATCH 21/23] Added continue from error cases in main-app.py for division by zero, square root of negative numbers, and logarithm of non-positive numbers. --- calculator.py | 26 +++++++++++++++++++++----- main-app.py | 21 ++++++++++++++++----- 2 files changed, 37 insertions(+), 10 deletions(-) diff --git a/calculator.py b/calculator.py index 531fd80..2bf9ebd 100644 --- a/calculator.py +++ b/calculator.py @@ -16,7 +16,7 @@ def mult(self, x, y): def div(self, x, y): if y == 0: - print("\nError: Division by zero is not defined.") + print("\nError: Division by zero is not defined.", end="") return None else: return x / y @@ -25,7 +25,11 @@ def sqr(self, x): return x * x def root2(self, x): - return math.sqrt(x) + if x < 0: + print("\nError: Square root of a negative number is not defined in the real number system.", end="") + return None + else: + return math.sqrt(x) def exp(self, x, y): return math.pow(x, y) @@ -64,16 +68,28 @@ def fac(self, x): return math.factorial(x) def log(self, x): - return math.log(x) + if x <= 0: + print("\nError: Logarithm of non-positive numbers is not defined.", end="") + return None + else: + return math.log(x) def log10(self, x): - return math.log10(x) + if x <= 0: + print("\nError: Logarithm of non-positive numbers is not defined.", end="") + return None + else: + return math.log10(x) def natlog(self, x): return math.log1p(x) def in_natlog(self, x): - return math.pow(math.log1p(x),-1) + if x <= 0: + print("\nError: Inverse logarithm of numbers less than or equal to 0 is not defined.", end="") + return None + else: + return math.pow(math.log1p(x),-1) def infinity(self, x): return math.isfinite(x) diff --git a/main-app.py b/main-app.py index 9fa26a4..a95e755 100644 --- a/main-app.py +++ b/main-app.py @@ -156,7 +156,6 @@ def performCalcLoop(calc, dis): a, b = getTwoNumbers(result_history) result = calc.div(a, b) if b == 0: - result_format = f"{a} / {b} = Error (division by zero is not allowed)" continue else: result_format = f"{a} / {b} = {result}" @@ -171,7 +170,10 @@ def performCalcLoop(calc, dis): print("\nFormat: sqrt([number])") a = getOneNumber(result_history) result = calc.root2(a) - result_format = f"sqrt({a}) = {result}" + if a < 0: + continue + else: + result_format = f"sqrt({a}) = {result}" elif choice == 'exp': print("\nFormat: [number1] ^ [number2]") @@ -256,13 +258,19 @@ def performCalcLoop(calc, dis): print("\nFormat: log([number])") a = getOneNumber(result_history) result = calc.log(a) - result_format = f"log({a}) = {result}" + if a <= 0: + continue + else: + result_format = f"log({a}) = {result}" elif choice == 'log10': print("\nFormat: log10([number])") a = getOneNumber(result_history) result = calc.log10(a) - result_format = f"log10({a}) = {result}" + if a <= 0: + continue + else: + result_format = f"log10({a}) = {result}" elif choice == 'natlog': print("\nFormat: ln([number])") @@ -274,7 +282,10 @@ def performCalcLoop(calc, dis): print("\nFormat: in_ln([number])") a = getOneNumber(result_history) result = calc.in_natlog(a) - result_format = f"in_ln({a}) = {result}" + if result is None: + continue + else: + result_format = f"in_ln({a}) = {result}" elif choice == 'finite': print("\nFormat: finite([number])") From 44ab8adfa1162b82962eaa2632fdc8ce42ecf028 Mon Sep 17 00:00:00 2001 From: david Date: Sun, 1 Mar 2026 18:07:21 -0500 Subject: [PATCH 22/23] Simplified using history in operations by using one fuction callout when needed --- main-app.py | 71 ++++++++++++++++++++--------------------------------- 1 file changed, 26 insertions(+), 45 deletions(-) diff --git a/main-app.py b/main-app.py index a95e755..e5fea09 100644 --- a/main-app.py +++ b/main-app.py @@ -1,63 +1,44 @@ from calculator import Calculator from Display_functions import Display +def history_call(value, result_history): + if value == "h": + while True: + Display.display_history(None, "h", result_history) + value = input("\nEnter the index of the history value you wish to use or 'e' to return to number input \nIndex: ") + if value == "e": + return None + value = int(value) + value = Display.history_call(None, value, result_history) + if value is not None: + print(f"\nUsing history value: {value}") + value = float(value) + return value + else: + continue + else: + value = float(value) + return value + + def getTwoNumbers(result_history): while True: a = input("\nIf wish to use history input 'h' else input number \nfirst number? ") - if a == "h": - while True: - Display.display_history(None, "h", result_history) - a = input("\nEnter the index of the history value you wish to use or 'e' to return to number input \nIndex: ") - if a == "e": - break - a = int(a) - a = Display.history_call(None, a, result_history) - if a is not None: - break - if a == "e": - continue - else: - print(f"\nUsing history value: {a}") - break - else: - a = float(a) + a = history_call(a, result_history) + if a is not None: break while True: b = input("\nIf wish to use history input 'h' else input number \nsecond number? ") - if b == "h": - Display.display_history(None, "h", result_history) - while True: - b = input("\nEnter the index of the history value you wish to use or 'e' to return to number input \nIndex: ") - if b == "e": - break - b = int(b) - b = Display.history_call(None, b, result_history) - if b is not None: - break - print(f"\nUsing history value: {b}") - break - else: - b = float(b) + b = history_call(b, result_history) + if b is not None: break return a, b def getOneNumber(result_history): while True: a = input("\nIf wish to use history input 'h' else input number \nnumber? ") - if a == "h": - while True: - Display.display_history(None, "h", result_history) - a = input("\nEnter the index of the history value you wish to use or 'e' to return to number input \nIndex: ") - if a == "e": - break - a = int(a) - a = Display.history_call(None, a, result_history) - if a is not None: - break - print(f"\nUsing history value: {a}") - break - else: - a = float(a) + a = history_call(a, result_history) + if a is not None: break return a From 577470fd125eed1530b53e0eaed5e979f69a3255 Mon Sep 17 00:00:00 2001 From: david Date: Sun, 1 Mar 2026 18:17:23 -0500 Subject: [PATCH 23/23] Fixed string statement --- main-app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main-app.py b/main-app.py index e5fea09..d36a845 100644 --- a/main-app.py +++ b/main-app.py @@ -76,7 +76,7 @@ def performCalcLoop(calc, dis): while True: print("\n") - choice = input("Type help for a list of operations or enter an operation \noperation: ") + choice = input("Type 'help' for a list of operations or enter an operation \noperation: ") switch = dis.switch_display_mode(choice, switch) # Switch display mode if the user input is a display mode command memory = dis.store_memory(choice, memory, result) # Store the user's choice in memory