From d1a6118ba875a64c5c88cfafec0798c0bbf218a8 Mon Sep 17 00:00:00 2001 From: Drake Dwornik Date: Fri, 29 Oct 2021 20:52:03 -0400 Subject: [PATCH 01/44] built a working add skeleton --- buttons.md | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ temp.py | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+) create mode 100644 buttons.md create mode 100644 temp.py diff --git a/buttons.md b/buttons.md new file mode 100644 index 0000000..957fe5c --- /dev/null +++ b/buttons.md @@ -0,0 +1,54 @@ +#list of calculator buttons and function definitions +##Core +`state` <- represents the screen + +`get current number on display` + +`clear the display` + +`add` +add(a: float, b:float) -> float + +`sub` +sub(a: float, b:float) -> float + +`multiply` + +`divide` + +`squre` + +`square_root` + +`exponentiate` + +`inverse` + +`invert_sign` + +##scientific +###Display +`switch_display_rotate` +`switch_display_str` +`display_binary` +`display_octal` +`display_decimal` +`display_hex` +###memmory +* store 1 value (for recall) + +`m+` (puts display in memory) +`mc` (clears memory) +`mrc` (puts memory on screen) + +###trig +`sin` +`cos` +`tan` +`asin` (inverse) +`acos` +`atan` +###switch trig mode +rads and degrees +rads_degrees_swap() -> str +switch and string \ No newline at end of file diff --git a/temp.py b/temp.py new file mode 100644 index 0000000..5c71867 --- /dev/null +++ b/temp.py @@ -0,0 +1,33 @@ +state = 0 +screen_number = 0 +command = "" +display_mode = "decimal" + +def add(a,b): + return a + b + + +def compute_state(screen_number): + if display_mode == "decimal": + return str(screen_number) + elif display_mode == "hex": + pass + + +while True: + state = compute_state(screen_number) + print("current state:", state) + user_entry = input("please enter something?") + if user_entry.isnumeric(): + user_entry = float(user_entry) + if command == "": + screen_number = user_entry + elif command == "add": + screen_number = add(screen_number,user_entry) + elif command == "sub": + sub(screen_number,user_entry) + elif user_entry == "exit": + break + else: + command = user_entry +print("thanks for pushing all my buttons") From 8ff48a6c9f2964ff60995762db37272afbb4940b Mon Sep 17 00:00:00 2001 From: Drake Dwornik Date: Fri, 29 Oct 2021 20:55:16 -0400 Subject: [PATCH 02/44] trying to fix git --- buttons.md | 2 +- calculator.py | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/buttons.md b/buttons.md index 957fe5c..43df6bb 100644 --- a/buttons.md +++ b/buttons.md @@ -25,7 +25,7 @@ sub(a: float, b:float) -> float `inverse` `invert_sign` - + ##scientific ###Display `switch_display_rotate` diff --git a/calculator.py b/calculator.py index 3c85ead..44ecd46 100644 --- a/calculator.py +++ b/calculator.py @@ -1,3 +1,13 @@ +class state: + def __init__(self): + value = 0 + display = "0" + + def display_decimal(self): + + + + class Calculator: def __init__(self): From 282fd7415795f50cd46f6071a67d65aae4568095 Mon Sep 17 00:00:00 2001 From: Drake Dwornik Date: Fri, 29 Oct 2021 21:46:10 -0400 Subject: [PATCH 03/44] made a state object --- calc.py | 30 ++++++++++++++++++++++++++++++ calculator.py | 32 +++++++++++++++++++++++++++++--- temp.py | 33 --------------------------------- 3 files changed, 59 insertions(+), 36 deletions(-) create mode 100644 calc.py delete mode 100644 temp.py diff --git a/calc.py b/calc.py new file mode 100644 index 0000000..f363ddb --- /dev/null +++ b/calc.py @@ -0,0 +1,30 @@ +from calculator import state + +state = state() + + +def add(a,b): + state.command = None + return a + b + + + + +while True: + state.print() + if state.command != None: + print("current command is:", state.command) + state.user_entry = input("please enter a mathematical function or number: ") + if state.user_entry.isnumeric(): + state.user_entry = float(state.user_entry) + if state.command == None: + state.value = state.user_entry + elif state.command == "add": + state.value = add(state.value,state.user_entry) + elif state.command == "sub": + sub(state.value,user_entry) + elif state.user_entry == "exit": + break + else: + state.command = state.user_entry +print("thanks for pushing all my buttons") diff --git a/calculator.py b/calculator.py index 44ecd46..7b906b3 100644 --- a/calculator.py +++ b/calculator.py @@ -1,10 +1,36 @@ class state: def __init__(self): - value = 0 - display = "0" + self.value = 0 + self.command = None + self.display_mode = "decimal" + self.trig_mode = "rads" + self.display = "0" + self.user_entry = None - def display_decimal(self): + def get_current_value(self): + pass + + + def print(self): + if self.display_mode == "decimal": + self.display = str(self.value) + elif self.display_mode == "hex": + self.display = hex(self.value) + elif self.display_mode == "binary": + pass + elif self.display_mode == "octal": + pass + else: + self.error() + print("current display is:",self.display) + + + + def error(self): + self.value = None + self.command = None + self.display_mode = "Err" diff --git a/temp.py b/temp.py deleted file mode 100644 index 5c71867..0000000 --- a/temp.py +++ /dev/null @@ -1,33 +0,0 @@ -state = 0 -screen_number = 0 -command = "" -display_mode = "decimal" - -def add(a,b): - return a + b - - -def compute_state(screen_number): - if display_mode == "decimal": - return str(screen_number) - elif display_mode == "hex": - pass - - -while True: - state = compute_state(screen_number) - print("current state:", state) - user_entry = input("please enter something?") - if user_entry.isnumeric(): - user_entry = float(user_entry) - if command == "": - screen_number = user_entry - elif command == "add": - screen_number = add(screen_number,user_entry) - elif command == "sub": - sub(screen_number,user_entry) - elif user_entry == "exit": - break - else: - command = user_entry -print("thanks for pushing all my buttons") From 1c966b73bc9eff3e7340b87352fcb797eb734c5b Mon Sep 17 00:00:00 2001 From: Drake Dwornik Date: Fri, 29 Oct 2021 22:13:21 -0400 Subject: [PATCH 04/44] object oriented funtions --- calculator.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/calculator.py b/calculator.py index 7b906b3..9d4850b 100644 --- a/calculator.py +++ b/calculator.py @@ -1,4 +1,7 @@ class state: + """ + initiates a calculator object + """ def __init__(self): self.value = 0 self.command = None @@ -26,13 +29,17 @@ def print(self): print("current display is:",self.display) - def error(self): self.value = None self.command = None self.display_mode = "Err" + def add(self,n): + self.value = self.value + n + def help(self): + print("You may enter a number or a command. They command will act on the displayed numnber, or wait for a second number to take action") + print("the commands are +, -, *, /, Square, SquareRoot, ^, Invert, ClearError, SwitchSign, Decimal, Binary, Octal, Hex, ToggleDisplayStyle, M+, MC, MRC, Sine, Cosine, Tangent, ASine, ACosine, Atangent, SwitchTrigMode, Rads, Degrees, !, Log, 10^x, Ln, e^x") class Calculator: From da0c6b0107076f9ac3f2f04747facbd70b0db74b Mon Sep 17 00:00:00 2001 From: Drake Dwornik Date: Fri, 29 Oct 2021 22:16:28 -0400 Subject: [PATCH 05/44] add is not a method of state --- calc2.py | 27 +++++++++++++++++++++++++++ calculator.py | 1 + 2 files changed, 28 insertions(+) create mode 100644 calc2.py diff --git a/calc2.py b/calc2.py new file mode 100644 index 0000000..5d5b7ae --- /dev/null +++ b/calc2.py @@ -0,0 +1,27 @@ +from calculator import state + +state = state() + + + + + + +while True: + state.print() + if state.command != None: + print("current command is:", state.command) + state.user_entry = input("please enter a mathematical function or number: ") + if state.user_entry.isnumeric(): + state.user_entry = float(state.user_entry) + if state.command == None: + state.value = state.user_entry + elif state.command == "add": + state.add(state.user_entry) + elif state.command == "sub": + sub(state.value,user_entry) + elif state.user_entry == "exit": + break + else: + state.command = state.user_entry +print("thanks for pushing all my buttons") diff --git a/calculator.py b/calculator.py index 9d4850b..d088242 100644 --- a/calculator.py +++ b/calculator.py @@ -36,6 +36,7 @@ def error(self): def add(self,n): self.value = self.value + n + self.command = None def help(self): print("You may enter a number or a command. They command will act on the displayed numnber, or wait for a second number to take action") From 1f646f9d9cd9b65e262acc3f0320eb5b1bcd38b7 Mon Sep 17 00:00:00 2001 From: Drake Dwornik Date: Fri, 29 Oct 2021 22:20:04 -0400 Subject: [PATCH 06/44] matched calc and calc2 --- calc.py | 7 ++----- calc2.py | 2 +- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/calc.py b/calc.py index f363ddb..7fdd7d3 100644 --- a/calc.py +++ b/calc.py @@ -3,9 +3,6 @@ state = state() -def add(a,b): - state.command = None - return a + b @@ -20,9 +17,9 @@ def add(a,b): if state.command == None: state.value = state.user_entry elif state.command == "add": - state.value = add(state.value,state.user_entry) + state.add(state.user_entry) elif state.command == "sub": - sub(state.value,user_entry) + state.sub(state.user_entry) elif state.user_entry == "exit": break else: diff --git a/calc2.py b/calc2.py index 5d5b7ae..7fdd7d3 100644 --- a/calc2.py +++ b/calc2.py @@ -19,7 +19,7 @@ elif state.command == "add": state.add(state.user_entry) elif state.command == "sub": - sub(state.value,user_entry) + state.sub(state.user_entry) elif state.user_entry == "exit": break else: From 9d08e210bef0f08487173df2b1215b923218d1e2 Mon Sep 17 00:00:00 2001 From: Drake Dwornik Date: Fri, 29 Oct 2021 22:23:24 -0400 Subject: [PATCH 07/44] capitalized the command input --- calc.py | 12 +++++++----- calc2.py | 27 --------------------------- 2 files changed, 7 insertions(+), 32 deletions(-) delete mode 100644 calc2.py diff --git a/calc.py b/calc.py index 7fdd7d3..9d2182e 100644 --- a/calc.py +++ b/calc.py @@ -11,17 +11,19 @@ state.print() if state.command != None: print("current command is:", state.command) - state.user_entry = input("please enter a mathematical function or number: ") + state.user_entry = input("please enter a mathematical function or number (or type help): ") if state.user_entry.isnumeric(): state.user_entry = float(state.user_entry) if state.command == None: state.value = state.user_entry - elif state.command == "add": + elif state.command == "+": state.add(state.user_entry) - elif state.command == "sub": + elif state.command == "-": state.sub(state.user_entry) - elif state.user_entry == "exit": + elif state.command == "HELP": + state.help() + elif state.user_entry == "EXIT": break else: - state.command = state.user_entry + state.command = state.user_entry.capitalize() print("thanks for pushing all my buttons") diff --git a/calc2.py b/calc2.py deleted file mode 100644 index 7fdd7d3..0000000 --- a/calc2.py +++ /dev/null @@ -1,27 +0,0 @@ -from calculator import state - -state = state() - - - - - - -while True: - state.print() - if state.command != None: - print("current command is:", state.command) - state.user_entry = input("please enter a mathematical function or number: ") - if state.user_entry.isnumeric(): - state.user_entry = float(state.user_entry) - if state.command == None: - state.value = state.user_entry - elif state.command == "add": - state.add(state.user_entry) - elif state.command == "sub": - state.sub(state.user_entry) - elif state.user_entry == "exit": - break - else: - state.command = state.user_entry -print("thanks for pushing all my buttons") From 8a66b9a6510f0a9126fc6938eaaa498b6b161415 Mon Sep 17 00:00:00 2001 From: Drake Dwornik Date: Fri, 29 Oct 2021 22:32:26 -0400 Subject: [PATCH 08/44] capitalized the command input --- calc.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/calc.py b/calc.py index 9d2182e..819b1ad 100644 --- a/calc.py +++ b/calc.py @@ -20,10 +20,11 @@ state.add(state.user_entry) elif state.command == "-": state.sub(state.user_entry) - elif state.command == "HELP": - state.help() - elif state.user_entry == "EXIT": + elif state.user_entry.upper() == "HELP": + state.help() + continue + elif state.user_entry.upper() == "EXIT": break else: - state.command = state.user_entry.capitalize() + state.command = state.user_entry.upper() print("thanks for pushing all my buttons") From 7caf9b8d93504e625473a0202b3f1257d9c70511 Mon Sep 17 00:00:00 2001 From: Drake Dwornik Date: Fri, 29 Oct 2021 22:39:14 -0400 Subject: [PATCH 09/44] cleaned up style --- calc.py | 13 ++++--------- calculator.py | 31 +++++++++++-------------------- 2 files changed, 15 insertions(+), 29 deletions(-) diff --git a/calc.py b/calc.py index 819b1ad..a979e76 100644 --- a/calc.py +++ b/calc.py @@ -1,20 +1,15 @@ -from calculator import state - -state = state() - - - - +from calculator import State +state = State() while True: state.print() - if state.command != None: + if state.command is None: print("current command is:", state.command) state.user_entry = input("please enter a mathematical function or number (or type help): ") if state.user_entry.isnumeric(): state.user_entry = float(state.user_entry) - if state.command == None: + if state.command is None: state.value = state.user_entry elif state.command == "+": state.add(state.user_entry) diff --git a/calculator.py b/calculator.py index d088242..909ab66 100644 --- a/calculator.py +++ b/calculator.py @@ -1,7 +1,8 @@ -class state: +class State: """ initiates a calculator object """ + def __init__(self): self.value = 0 self.command = None @@ -10,11 +11,9 @@ def __init__(self): self.display = "0" self.user_entry = None - def get_current_value(self): pass - def print(self): if self.display_mode == "decimal": self.display = str(self.value) @@ -26,31 +25,23 @@ def print(self): pass else: self.error() - print("current display is:",self.display) - + print("current display is:", self.display) def error(self): self.value = None self.command = None self.display_mode = "Err" - def add(self,n): + def add(self, n): self.value = self.value + n self.command = None def help(self): - print("You may enter a number or a command. They command will act on the displayed numnber, or wait for a second number to take action") - print("the commands are +, -, *, /, Square, SquareRoot, ^, Invert, ClearError, SwitchSign, Decimal, Binary, Octal, Hex, ToggleDisplayStyle, M+, MC, MRC, Sine, Cosine, Tangent, ASine, ACosine, Atangent, SwitchTrigMode, Rads, Degrees, !, Log, 10^x, Ln, e^x") - -class Calculator: + print( + "You may enter a number or a command. They command will act on the displayed number, or wait for a second number to take action") + print( + "the commands are +, -, *, /, Square, SquareRoot, ^, Invert, ClearError, SwitchSign, Decimal, Binary, Octal, Hex, ToggleDisplayStyle, M+, MC, MRC, Sine, Cosine, Tangent, ASine, ACosine, ATangent, SwitchTrigMode, Rads, Degrees, !, Log, 10^x, Ln, e^x") - 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. + def sub(self, n): + self.value = self.value - n + self.command = None From f53afaf58755dd93cd94ad3a7a68b8e2195825c7 Mon Sep 17 00:00:00 2001 From: Roethel Christine Date: Sat, 30 Oct 2021 15:46:02 -0400 Subject: [PATCH 10/44] CR test 1 --- calculator.py | 39 ++++++++++++++--- main-app.py | 117 ++++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 129 insertions(+), 27 deletions(-) diff --git a/calculator.py b/calculator.py index 3c85ead..6a9a7be 100644 --- a/calculator.py +++ b/calculator.py @@ -1,12 +1,41 @@ -class Calculator: +import math +class Calculator: def __init__(self): pass - def add(self, x, y): + def add(x, y): + print(x + y) return x + y - def sub(self, x, y): - return 0 + def subtract(x, y): + print(x - y) + return x - y + + def multiply(x, y): + print(x * y) + return y * x + + def divide(x, y): + print(x / y) + return x / y + + + def square(base): + print(base ** 2) + return base ** 2 + + + def exp(x, y): + print(x ** y) + return x ** y + + + def square_root(x): + print(x ** (1 / 2)) + return x ** (1 / 2) + -# add lots more methods to this calculator class. + def inv(x): + print(1 / x) + return 1 / x \ No newline at end of file diff --git a/main-app.py b/main-app.py index a7cc4e2..d156570 100644 --- a/main-app.py +++ b/main-app.py @@ -1,34 +1,107 @@ from calculator import Calculator +import math +import decimal +global mem +mem = 0 -def getTwoNumbers(): - a = float(input("first number? ")) - b = float(input("second number? ")) - return a, b +def enter_num(): + num1 = float(input()) + return num1 +def screen_options(): + print("1: Add") + print("2: Subtract") + print("3: Multiply") + print("4: Divide") + print("5: Square") + print("6: Square Root") + print("7: Exponent") + print("8: Exit") + print("") + Operation = int(input('Choose an operation: (Select the number) ')) + memStore = None -def displayResult(x: float): - print(x, "\n") + if Operation == 1: + print("Add") + print("Enter the first number: ") + x = enter_num() + print("Enter the second number: ") + y = enter_num() + result = add(x, y) + return result + elif Operation == 2: + print("Subtract") + print('Enter the first number: ') + x = enter_num() + print('Enter the second number: ') + y = enter_num() + result = subtract(x, y) + return result -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)) + elif Operation == 3: + print('Multiply') + print('Enter the first number: ') + x = enter_num() + print('Enter the second number: ') + y = enter_num() + result = multiply(x, y) + return result + + elif Operation == 4: + print("Divide") + print("Enter the first number: ") + x = enter_num() + print("Enter the second number: ") + y = enter_num() + if y == 0: + print("ERROR") + return None else: - print("That is not a valid input.") + result = divide(x, y) + return result + + elif Operation == 5: + print("Square") + print('Enter a number to square: ') + base = enter_num() + result = square(base) + return result + + elif Operation == 6: + print("Exponent") + print("Enter the base number: ") + x = enter_num() + print("Enter the exponent") + y = enter_num() + result = exp(x, y) + return result + + elif Operation == 7: + print("Square Root") + print("Enter the number: ") + x = enter_num() + result = square_root(x) + return result + + elif Operation == 8: + print("Inverse") + x = enter_num() + result = inv(x) + return result + + elif Operation == 8: + condi = False + print("Thank you for pushing my buttons!") + +###################################################################### +## on screen ## -# main start -def main(): - calc = Calculator() - performCalcLoop(calc) - print("Done Calculating.") +print("Welcome to our Calculator!") +print("How can we help you?") +print("") -if __name__ == '__main__': - main() +screen_options() From 8737e4f822c7ee7247c661b92dcf7648cdd2bebc Mon Sep 17 00:00:00 2001 From: Roethel Christine Date: Sat, 30 Oct 2021 18:20:28 -0400 Subject: [PATCH 11/44] CR test 2 --- calculator.py | 39 ++++++++++-------- main-app.py | 111 ++++++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 116 insertions(+), 34 deletions(-) diff --git a/calculator.py b/calculator.py index 6a9a7be..dabd4eb 100644 --- a/calculator.py +++ b/calculator.py @@ -1,41 +1,46 @@ import math class Calculator: + def __init__(self): pass - def add(x, y): - print(x + y) - return x + y - def subtract(x, y): - print(x - y) + def add(self, a, b): + print(self, a + b) + return a + b + + + def subtract(self, x, y): + print(self, x - y) return x - y - def multiply(x, y): - print(x * y) + + def multiply(self, x, y): + print(self, x * y) return y * x - def divide(x, y): - print(x / y) + + def divide(self, x, y): + print(self, x / y) return x / y - def square(base): - print(base ** 2) + def square(self, base): + print(self, base ** 2) return base ** 2 - def exp(x, y): - print(x ** y) + def exp(self, x, y): + print(self, x ** y) return x ** y - def square_root(x): - print(x ** (1 / 2)) + def square_root(self, x): + print(self, x ** (1 / 2)) return x ** (1 / 2) - def inv(x): - print(1 / x) + def inv(self, x): + print(self, 1 / x) return 1 / x \ No newline at end of file diff --git a/main-app.py b/main-app.py index d156570..34cb38b 100644 --- a/main-app.py +++ b/main-app.py @@ -2,6 +2,12 @@ import math import decimal +calc=Calculator() + +def enter_num(): + num1 = float(input()) + return num1 + global mem mem = 0 @@ -10,14 +16,13 @@ def enter_num(): return num1 def screen_options(): - print("1: Add") - print("2: Subtract") - print("3: Multiply") - print("4: Divide") - print("5: Square") - print("6: Square Root") - print("7: Exponent") - print("8: Exit") + print("1: Add 8: Inverse 15: M+") + print("2: Subtract 9: Sine 16: MC") + print("3: Multiply 10: Cosine 17: MRC") + print("4: Divide 11: Tangent 18: Exit") + print("5: Square 12: Inverse Sine") + print("6: Square Root 13: Inverse Consine") + print("7: Exponent 14: Inverse Tangent") print("") Operation = int(input('Choose an operation: (Select the number) ')) memStore = None @@ -28,7 +33,7 @@ def screen_options(): x = enter_num() print("Enter the second number: ") y = enter_num() - result = add(x, y) + result = calc.add(x, y) return result elif Operation == 2: @@ -37,7 +42,7 @@ def screen_options(): x = enter_num() print('Enter the second number: ') y = enter_num() - result = subtract(x, y) + result = calc.subtract(x, y) return result elif Operation == 3: @@ -46,7 +51,7 @@ def screen_options(): x = enter_num() print('Enter the second number: ') y = enter_num() - result = multiply(x, y) + result = calc.multiply(x, y) return result elif Operation == 4: @@ -59,12 +64,12 @@ def screen_options(): print("ERROR") return None else: - result = divide(x, y) + result = calc.divide(x, y) return result elif Operation == 5: print("Square") - print('Enter a number to square: ') + print("Enter the number: ") base = enter_num() result = square(base) return result @@ -75,23 +80,95 @@ def screen_options(): x = enter_num() print("Enter the exponent") y = enter_num() - result = exp(x, y) + result = calc.exp(x, y) return result elif Operation == 7: print("Square Root") print("Enter the number: ") x = enter_num() - result = square_root(x) + result = calc.square_root(x) return result elif Operation == 8: print("Inverse") + print("Enter the number: ") x = enter_num() - result = inv(x) + result = calc.inv(x) return result - elif Operation == 8: +##TRIG FUNCTIONS +##must add statements for degrees/radians + + elif Operation == 9: + print("Sine") + print("Enter the number: ") + x = enter_num() + result = calc.square_root(x) + return result + + + elif Operation == 10: + print("Cosine") + print("Enter the number: ") + x = enter_num() + result = calc.square_root(x) + return result + + + elif Operation == 11: + print("Tangent") + print("Enter the number: ") + x = enter_num() + result = calc.square_root(x) + return result + + + elif Operation == 12: + print("Inverse Sine") + print("Enter the number: ") + x = enter_num() + result = calc.square_root(x) + return result + + elif Operation == 13: + print("Inverse Cosine") + print("Enter the number: ") + x = enter_num() + result = calc.square_root(x) + return result + + elif Operation == 14: + print("Inverse Tangent") + print("Enter the number: ") + x = enter_num() + result = calc.square_root(x) + return result + + + elif Operation == 15: + print("M+") + print("Enter the number: ") + x = enter_num() + result = calc.square_root(x) + return result + + + elif Operation == 16: + print("MC") + print("Enter the number: ") + x = enter_num() + result = calc.square_root(x) + return result + + elif Operation == 17: + print("MCR") + print("Enter the number: ") + x = enter_num() + result = calc.square_root(x) + return result + + elif Operation == 18: condi = False print("Thank you for pushing my buttons!") From ff0defaafaf4d6441506f74abc04f9da29e96d80 Mon Sep 17 00:00:00 2001 From: Roethel Christine Date: Sat, 30 Oct 2021 18:39:48 -0400 Subject: [PATCH 12/44] CR test 3 --- main-app.py | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/main-app.py b/main-app.py index 34cb38b..86325d1 100644 --- a/main-app.py +++ b/main-app.py @@ -8,8 +8,6 @@ def enter_num(): num1 = float(input()) return num1 -global mem -mem = 0 def enter_num(): num1 = float(input()) @@ -25,7 +23,7 @@ def screen_options(): print("7: Exponent 14: Inverse Tangent") print("") Operation = int(input('Choose an operation: (Select the number) ')) - memStore = None + memStore = 0 if Operation == 1: print("Add") @@ -104,7 +102,7 @@ def screen_options(): print("Sine") print("Enter the number: ") x = enter_num() - result = calc.square_root(x) + result = calc.sine(x) return result @@ -112,7 +110,7 @@ def screen_options(): print("Cosine") print("Enter the number: ") x = enter_num() - result = calc.square_root(x) + result = calc.cosine(x) return result @@ -120,7 +118,7 @@ def screen_options(): print("Tangent") print("Enter the number: ") x = enter_num() - result = calc.square_root(x) + result = calc.tangent(x) return result @@ -128,45 +126,47 @@ def screen_options(): print("Inverse Sine") print("Enter the number: ") x = enter_num() - result = calc.square_root(x) + result = calc.invsine(x) return result elif Operation == 13: print("Inverse Cosine") print("Enter the number: ") x = enter_num() - result = calc.square_root(x) + result = calc.invcosine(x) return result elif Operation == 14: print("Inverse Tangent") print("Enter the number: ") x = enter_num() - result = calc.square_root(x) + result = calc.invtangent(x) return result +##MEMORY FUNCTIONS elif Operation == 15: print("M+") print("Enter the number: ") - x = enter_num() - result = calc.square_root(x) - return result + memStore = float(input("Enter a value to store: ")) + print(memStore) + return memStore elif Operation == 16: print("MC") - print("Enter the number: ") - x = enter_num() - result = calc.square_root(x) - return result + if type(memStore) != None: + print(memStore) elif Operation == 17: print("MCR") - print("Enter the number: ") - x = enter_num() - result = calc.square_root(x) - return result + store_choice = input("Do you want to clear memory? Y or N: ") + if store_choice == "y": + memStore = 0 + else: + pass + print(memStore) + return memStore elif Operation == 18: condi = False From d421f314ff189935c52ef3c5eb74f23507fec116 Mon Sep 17 00:00:00 2001 From: Roethel Christine Date: Sat, 30 Oct 2021 19:38:42 -0400 Subject: [PATCH 13/44] CR test 4 --- calculator.py | 24 ++++++++- main-app.py | 137 +++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 152 insertions(+), 9 deletions(-) diff --git a/calculator.py b/calculator.py index dabd4eb..443eea6 100644 --- a/calculator.py +++ b/calculator.py @@ -43,4 +43,26 @@ def square_root(self, x): def inv(self, x): print(self, 1 / x) - return 1 / x \ No newline at end of file + return 1 / x + + +##SECONDARY FORMULAS + + def add2(self, x): + print(self, returned_result + x) + return returned_result + x + + + def subtract2(self, x): + print(self, returned_result - x) + return returned_result - x + + + def multiply2(self, x): + print(self, returned_result * x) + return returned_result * x + + + def divide2(self, x): + print(self, returned_result / x) + return returned_result / x \ No newline at end of file diff --git a/main-app.py b/main-app.py index 86325d1..2e4670e 100644 --- a/main-app.py +++ b/main-app.py @@ -9,10 +9,6 @@ def enter_num(): return num1 -def enter_num(): - num1 = float(input()) - return num1 - def screen_options(): print("1: Add 8: Inverse 15: M+") print("2: Subtract 9: Sine 16: MC") @@ -22,8 +18,10 @@ def screen_options(): print("6: Square Root 13: Inverse Consine") print("7: Exponent 14: Inverse Tangent") print("") + Operation = int(input('Choose an operation: (Select the number) ')) - memStore = 0 + + memStore = None if Operation == 1: print("Add") @@ -160,8 +158,8 @@ def screen_options(): elif Operation == 17: print("MCR") - store_choice = input("Do you want to clear memory? Y or N: ") - if store_choice == "y": + store_choice = input("Do you want to clear memory? Y or N (case sensitive): ") + if store_choice == "Y": memStore = 0 else: pass @@ -172,7 +170,109 @@ def screen_options(): condi = False print("Thank you for pushing my buttons!") +##LOOPING OPERATIONS +###DEF FOR SECONDARY OPERATIONS + + +def choose_data_type(): + data_choice = int(input('Enter data type: 1. Decimal 2. Hexadecimal 3. Binary 4. Octal ')) + if data_choice == 1: + print(returned_result) + return returned_result + elif data_choice == 2: + print(hex(int(returned_result))) + return hex(int(returned_result)) + elif data_choice == 3: + print(bin(int(returned_result)).replace("0b", "")) + return bin(int(returned_result)).replace("0b", "") + elif data_choice == 4: + print(oct(int(returned_result))) + return oct(int(returned_result)) + + +def secondary_operation(): + print("1: Add 5: Square 9: M+") + print("2: Subtract 6: Square Root 10: MC") + print("3: Multiply 7: Exponent 11: MRC") + print("4: Divide 8: Inverse 12: Exit") + print("") + Operation = int(input('Choose an operation: ')) + + memStore = None + + if Operation == 1: + print("Add") + print("Enter number to add: ") + x = enter_num() + result = calc.add2(x) + return result + + elif Operation == 2: + print("Subtract") + print("Enter the number to subtract: ") + x = enter_num() + result = calc.subtract2(x) + return result + + elif Operation == 3: + print("Multiply") + print("Enter the second number: ") + x = enter_num() + result = calc.multiply2(x) + return result + + elif Operation == 4: + print("Divide") + print("Enter the second number: ") + x = enter_num() + result = calc.divide2(x) + return result + + elif Operation == 5: + print("Square") + result = square2(returned_result) + return result + + elif Operation == 6: + print("Exponent") + print("Enter the exponent: ") + x = enter_num() + result = calc.exp2(x) + return result + + elif Operation == 7: + print("Square Root") + result = calc.square_root2(returned_result) + return result + + elif Operation == 8: + print("Inverse") + result = inv2(returned_result) + return result + + elif Operation == 9: + memStore = returned_result + print(memStore) + return memStore + elif Operation == 10: + if type(memStore) != None: + print(memStore) + else: + print('Empty') + + elif Operation == 11: + store_choice = input("Do you want to clear memory? Y or N (case sensitive): ") + if store_choice == "Y": + memStore = 0 + else: + pass + print(memStore) + return memStore + + elif Operation == 12: + condi = False + print('Goodbye!') ###################################################################### ## on screen ## @@ -181,4 +281,25 @@ def screen_options(): print("How can we help you?") print("") -screen_options() + +condi = True +while condi: + returned_result = screen_options() + print(f"Result: {returned_result}") + choose_data_type() + print("") + cont = input("Continue with current value? Y or N (case sensitive): ") + print('') + if cont == "Y": + condi2 = True + while condi2: + returned_result = secondary_operation() + print(f"Result: {returned_result}") + choose_data_type() + print("") + cont2 = input("Continue with current value? Y or N (case sensitive): ") + print("") + if cont2 == "Y": + condi2 = True + else: + break \ No newline at end of file From 8a92d2deed1b6cc22086556ca96b142d50c47cae Mon Sep 17 00:00:00 2001 From: Naicker Creason Date: Sun, 31 Oct 2021 09:24:04 -0400 Subject: [PATCH 14/44] I added all math functions --- calculator.py | 60 +++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 46 insertions(+), 14 deletions(-) diff --git a/calculator.py b/calculator.py index 443eea6..ba0b54b 100644 --- a/calculator.py +++ b/calculator.py @@ -3,66 +3,98 @@ class Calculator: def __init__(self): - pass + self.degrees = True def add(self, a, b): - print(self, a + b) + print( a + b) return a + b def subtract(self, x, y): - print(self, x - y) + print( x - y) return x - y def multiply(self, x, y): - print(self, x * y) + print( x * y) return y * x def divide(self, x, y): - print(self, x / y) + print( x / y) return x / y def square(self, base): - print(self, base ** 2) + print( base ** 2) return base ** 2 def exp(self, x, y): - print(self, x ** y) + print( x ** y) return x ** y def square_root(self, x): - print(self, x ** (1 / 2)) + print( x ** (1 / 2)) return x ** (1 / 2) def inv(self, x): - print(self, 1 / x) + print( 1 / x) return 1 / x + def deg_rad_swap(self): + self.degrees = not self.degrees -##SECONDARY FORMULAS + def sin(self, x): + if self.degrees: + x = math.radians(x) + return math.sin(x) + + def cosine(self, x): + if self.degrees: + x = math.radians(x) + return math.cos(x) + + def tangent(self, x): + if self.degrees: + x = math.radians(x) + return math.tan(x) + + def inverse_sine(self, x): + if self.degrees: + x = math.radians(x) + return math.asin(x) + + def inverse_cosine(self, x): + if self.degrees: + x = math.radians(x) + return math.acos(x) + + def inverse_tangent(self, x): + if self.degrees: + x = math.radians(x) + return math.atan(x) + + ##SECONDARY FORMULAS def add2(self, x): - print(self, returned_result + x) + print( returned_result + x) return returned_result + x def subtract2(self, x): - print(self, returned_result - x) + print( returned_result - x) return returned_result - x def multiply2(self, x): - print(self, returned_result * x) + print( returned_result * x) return returned_result * x def divide2(self, x): - print(self, returned_result / x) + print( returned_result / x) return returned_result / x \ No newline at end of file From 14627b4aad372fbd5d99223f45c9c7c577838c56 Mon Sep 17 00:00:00 2001 From: Naicker Creason Date: Sun, 31 Oct 2021 10:02:14 -0400 Subject: [PATCH 15/44] added docstrings --- calculator.py | 101 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 100 insertions(+), 1 deletion(-) diff --git a/calculator.py b/calculator.py index ba0b54b..9bf7c30 100644 --- a/calculator.py +++ b/calculator.py @@ -7,73 +7,152 @@ def __init__(self): def add(self, a, b): + """ + ADDS TWO NUMBERS AND RETURNS RESULT + :param a: + :param b: + :return: + """ print( a + b) return a + b def subtract(self, x, y): + """ + SUBTRACTS TWO NUMBERS AND RETURNS RESULT + :param x: + :param y: + :return: + """ print( x - y) return x - y def multiply(self, x, y): + """ + MULTIPLIES TWO NUMBERS AND RETURNS RESULT + :param x: + :param y: + :return: + """ print( x * y) return y * x def divide(self, x, y): + """ + DIVIDES TWO NUMBERS AND RETURNS RESULT + :param x: + :param y: + :return: + """ print( x / y) return x / y def square(self, base): + """ + SQUARES A NUMBER AND RETURNS RESULT + :param base: + :return: + """ print( base ** 2) return base ** 2 def exp(self, x, y): + """ + EXPONENTIATES TWO NUMBERS AND RETURNS RESULT + :param x: + :param y: + :return: + """ print( x ** y) return x ** y def square_root(self, x): + """ + FINDS THE SQUARE ROOT OF A NUMBER AND RETURNS RESULT + :param x: + :return: + """ print( x ** (1 / 2)) return x ** (1 / 2) - def inv(self, x): + def inverse(self, x): + """ + INVERSES A NUMBER AND RETURNS RESULT + :param x: + :return: + """ print( 1 / x) return 1 / x def deg_rad_swap(self): + """ + SWAPS BETWEEN RADIANS AND DEGREES + :return: + """ self.degrees = not self.degrees def sin(self, x): + """ + FINDS SINE OF NUMBER AND RETURNS RESULT + :param x: + :return: + """ if self.degrees: x = math.radians(x) return math.sin(x) def cosine(self, x): + """ + FINDS COSINE OF NUMBER AND RETURNS RESULT + :param x: + :return: + """ if self.degrees: x = math.radians(x) return math.cos(x) def tangent(self, x): + """ + FINDS TANGENT OF NUMBER AND RETURNS RESULT + :param x: + :return: + """ if self.degrees: x = math.radians(x) return math.tan(x) def inverse_sine(self, x): + """ + FINDS INVERSE SINE OF NUMBER AND RETURNS RESULT + :param x: + :return: + """ if self.degrees: x = math.radians(x) return math.asin(x) def inverse_cosine(self, x): + """ + FINDS INVERSE COSINE OF NUMBER AND RETURNS RESULT + :param x: + :return: + """ if self.degrees: x = math.radians(x) return math.acos(x) def inverse_tangent(self, x): + """ + FINDS INVERSE TANGENT OF NUMBER AND RETURNS RESULT + :param x: + :return: + """ if self.degrees: x = math.radians(x) return math.atan(x) @@ -81,20 +160,40 @@ def inverse_tangent(self, x): ##SECONDARY FORMULAS def add2(self, x): + """ + ADDS A NUMBER WITH THE SAME NUMBER + :param x: + :return: + """ print( returned_result + x) return returned_result + x def subtract2(self, x): + """ + SUBTRACTS A NUMBER WITH THE SAME NUMBER + :param x: + :return: + """ print( returned_result - x) return returned_result - x def multiply2(self, x): + """ + MULTIPLIES A NUMBER WITH THE SAME NUMBER + :param x: + :return: + """ print( returned_result * x) return returned_result * x def divide2(self, x): + """ + DIVIDES A NUMBER WITH THE SAME NUMBER + :param x: + :return: + """ print( returned_result / x) return returned_result / x \ No newline at end of file From 3a608be62844bc297778bcbdde7fb45538877a40 Mon Sep 17 00:00:00 2001 From: Drake Dwornik Date: Sun, 31 Oct 2021 10:10:35 -0400 Subject: [PATCH 16/44] started adding error handling and tests --- calculator.py | 17 ++++-- main-app.py => main_app.py | 53 ++++++++++--------- test_calculator.py | 88 ++++++++++++++++++++++++++++++++ calctests.py => test_main-app.py | 4 +- 4 files changed, 132 insertions(+), 30 deletions(-) rename main-app.py => main_app.py (89%) create mode 100644 test_calculator.py rename calctests.py => test_main-app.py (87%) diff --git a/calculator.py b/calculator.py index 443eea6..7771ff8 100644 --- a/calculator.py +++ b/calculator.py @@ -1,9 +1,13 @@ -import math + class Calculator: def __init__(self): - pass + error = False + value = 0 + + def error(self): + self.error = True def add(self, a, b): @@ -22,8 +26,13 @@ def multiply(self, x, y): def divide(self, x, y): - print(self, x / y) - return x / y + try: + result = x / y + except: + result = "Err" + self.error() + + return result def square(self, base): diff --git a/main-app.py b/main_app.py similarity index 89% rename from main-app.py rename to main_app.py index 2e4670e..5a8e87e 100644 --- a/main-app.py +++ b/main_app.py @@ -5,8 +5,12 @@ calc=Calculator() def enter_num(): - num1 = float(input()) - return num1 + try: + num1 = float(input()) + return num1 + except: + calc.error() + def screen_options(): @@ -281,25 +285,26 @@ def secondary_operation(): print("How can we help you?") print("") - -condi = True -while condi: - returned_result = screen_options() - print(f"Result: {returned_result}") - choose_data_type() - print("") - cont = input("Continue with current value? Y or N (case sensitive): ") - print('') - if cont == "Y": - condi2 = True - while condi2: - returned_result = secondary_operation() - print(f"Result: {returned_result}") - choose_data_type() - print("") - cont2 = input("Continue with current value? Y or N (case sensitive): ") - print("") - if cont2 == "Y": - condi2 = True - else: - break \ No newline at end of file +def main(): + condi = True + while condi: + returned_result = screen_options() + print(f"Result: {returned_result}") + choose_data_type() + print("") + cont = input("Continue with current value? Y or N (case sensitive): ") + print('') + if cont == "Y": + condi2 = True + while condi2: + returned_result = secondary_operation() + print(f"Result: {returned_result}") + choose_data_type() + print("") + cont2 = input("Continue with current value? Y or N (case sensitive): ") + print("") + if cont2 == "Y": + condi2 = True + else: + break +main() \ No newline at end of file diff --git a/test_calculator.py b/test_calculator.py new file mode 100644 index 0000000..0eda498 --- /dev/null +++ b/test_calculator.py @@ -0,0 +1,88 @@ +import unittest +from calculator import Calculator + + + +def runTest(self, prompt_str, expected_out): + with patch('builtins.input', return_value=prompt_str), patch('sys.stdout', new=StringIO()) as fake_out: + answer() + self.assertEqual(enter_num(), expected_out) + + +class TestStringMethods(unittest.TestCase): + + def test_add(self): + c = Calculator() + self.assertEqual(c.add(3, 4), 7) + self.assertEqual(c.add(-3,-4), -7) + self.assertTrue(c.add(3,-4), -1) + + def test_subtract(self): + c = Calculator() + self.assertEqual(c.subtract(3, 4), -1) + self.assertEqual(c.subtract(-3,-4), 1) + self.assertTrue(c.subtract(3,-4), 7) + + def test_multiply(self): + c = Calculator() + self.assertEqual(c.multiply(3, 4), 12) + self.assertEqual(c.multiply(-3,-4), 12) + self.assertTrue(c.multiply(3,-4), -12) + def test_divide(self): + c = Calculator() + self.assertEqual(c.divide(3, 4), .75) + self.assertEqual(c.divide(-3,-4), .75) + self.assertEqual(c.divide(3,-4), -.75) + self.assertEqual(c.divide(3,0),"Err") + def test_square(self): + c = Calculator() + self.assertEqual(c.square(3), 9) + self.assertEqual(c.square(-4), 16) + self.assertEqual(c.square(0), 0) + def test_exp(self): + c = Calculator() + self.assertEqual(c.exp(3, 4), 81) + self.assertEqual(c.exp(3, -4), (1/3)*(1/3)*(1/3)*(1/3)) + self.assertEqual(c.exp(-3, -4), (-(1/3))*(-(1/3))*(-(1/3))*(-(1/3))) + self.assertEqual(c.exp(0, 0), 1) + def test_square_root(self): + c = Calculator() + self.assertEqual(c.add(5, 8), 13) + + def test_add2(self): + c = Calculator() + self.assertEqual(c.add(5, 8), 13) + + def test_subtract2(self): + c = Calculator() + self.assertEqual(c.add(5, 8), 13) + + def test_multiply2(self): + c = Calculator() + self.assertEqual(c.add(5, 8), 13) + + def test_divide2(self): + c = Calculator() + self.assertEqual(c.add(5, 8), 13) + + def test_inv(self): + c = Calculator() + self.assertEqual(c.add(5, 8), 13) + + def test_sine(self): + pass + + def test_cosine(self): + pass + + def test_tangent(self): + pass + + def test_invsine(self): + pass + + + + +if __name__ == '__main__': + unittest.main() diff --git a/calctests.py b/test_main-app.py similarity index 87% rename from calctests.py rename to test_main-app.py index 1964570..cd7ee5e 100644 --- a/calctests.py +++ b/test_main-app.py @@ -2,7 +2,7 @@ from calculator import Calculator -class TestStringMethods(unittest.TestCase): +class TestCalculatorMethods(unittest.TestCase): def test_add(self): c = Calculator() @@ -22,4 +22,4 @@ def test_sub(self): if __name__ == '__main__': - unittest.main() + unittest.main() \ No newline at end of file From fe386bb0c3f3c6dc9a916d846f7cff4227dda6a9 Mon Sep 17 00:00:00 2001 From: Drake Dwornik Date: Sun, 31 Oct 2021 11:06:11 -0400 Subject: [PATCH 17/44] added more tests, and error handling --- calculator.py | 21 +++++++++++++++------ test_calculator.py | 8 ++++++-- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/calculator.py b/calculator.py index 7771ff8..0f16a1c 100644 --- a/calculator.py +++ b/calculator.py @@ -1,4 +1,4 @@ - +import math class Calculator: @@ -6,7 +6,7 @@ def __init__(self): error = False value = 0 - def error(self): + def err(self): self.error = True @@ -30,7 +30,7 @@ def divide(self, x, y): result = x / y except: result = "Err" - self.error() + self.err() return result @@ -46,12 +46,21 @@ def exp(self, x, y): def square_root(self, x): - print(self, x ** (1 / 2)) - return x ** (1 / 2) + try: + print(math.sqrt(x)) + except: + self.err() + return "Err" + return math.sqrt(x) def inv(self, x): - print(self, 1 / x) + try: + result = 1/x + except: + self.err() + return "Err" + print(1 / x) return 1 / x diff --git a/test_calculator.py b/test_calculator.py index 0eda498..d099528 100644 --- a/test_calculator.py +++ b/test_calculator.py @@ -47,7 +47,9 @@ def test_exp(self): self.assertEqual(c.exp(0, 0), 1) def test_square_root(self): c = Calculator() - self.assertEqual(c.add(5, 8), 13) + self.assertEqual(c.square_root(-2), "Err") + self.assertEqual(c.square_root(9), 3) + self.assertEqual(c.square_root(0),0) def test_add2(self): c = Calculator() @@ -67,7 +69,9 @@ def test_divide2(self): def test_inv(self): c = Calculator() - self.assertEqual(c.add(5, 8), 13) + self.assertEqual(c.inv(5), .2) + self.assertEqual(c.inv(0), "Err") + self.assertEqual(c.inv(-5), -.2) def test_sine(self): pass From a1ce2f45bc11e7487c0665421ae77f2c573d9aad Mon Sep 17 00:00:00 2001 From: Naicker Creason Date: Sun, 31 Oct 2021 11:48:55 -0400 Subject: [PATCH 18/44] uploaded to memory branch --- calculator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/calculator.py b/calculator.py index 9bf7c30..42544a0 100644 --- a/calculator.py +++ b/calculator.py @@ -196,4 +196,4 @@ def divide2(self, x): :return: """ print( returned_result / x) - return returned_result / x \ No newline at end of file + return returned_result / x From 9a244fff55ae35b8469166a89bfadd28d52f06c1 Mon Sep 17 00:00:00 2001 From: Roethel Christine Date: Sun, 31 Oct 2021 12:43:19 -0400 Subject: [PATCH 19/44] testing branch --- new | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 new diff --git a/new b/new new file mode 100644 index 0000000..e69de29 From 4d6532f2ed87d7f5d12418a4367e197788361488 Mon Sep 17 00:00:00 2001 From: Roethel Christine Date: Sun, 31 Oct 2021 13:09:12 -0400 Subject: [PATCH 20/44] trying to test --- main-app.py | 305 ---------------------------------------------------- 1 file changed, 305 deletions(-) delete mode 100644 main-app.py diff --git a/main-app.py b/main-app.py deleted file mode 100644 index 2e4670e..0000000 --- a/main-app.py +++ /dev/null @@ -1,305 +0,0 @@ -from calculator import Calculator -import math -import decimal - -calc=Calculator() - -def enter_num(): - num1 = float(input()) - return num1 - - -def screen_options(): - print("1: Add 8: Inverse 15: M+") - print("2: Subtract 9: Sine 16: MC") - print("3: Multiply 10: Cosine 17: MRC") - print("4: Divide 11: Tangent 18: Exit") - print("5: Square 12: Inverse Sine") - print("6: Square Root 13: Inverse Consine") - print("7: Exponent 14: Inverse Tangent") - print("") - - Operation = int(input('Choose an operation: (Select the number) ')) - - memStore = None - - if Operation == 1: - print("Add") - print("Enter the first number: ") - x = enter_num() - print("Enter the second number: ") - y = enter_num() - result = calc.add(x, y) - return result - - elif Operation == 2: - print("Subtract") - print('Enter the first number: ') - x = enter_num() - print('Enter the second number: ') - y = enter_num() - result = calc.subtract(x, y) - return result - - elif Operation == 3: - print('Multiply') - print('Enter the first number: ') - x = enter_num() - print('Enter the second number: ') - y = enter_num() - result = calc.multiply(x, y) - return result - - elif Operation == 4: - print("Divide") - print("Enter the first number: ") - x = enter_num() - print("Enter the second number: ") - y = enter_num() - if y == 0: - print("ERROR") - return None - else: - result = calc.divide(x, y) - return result - - elif Operation == 5: - print("Square") - print("Enter the number: ") - base = enter_num() - result = square(base) - return result - - elif Operation == 6: - print("Exponent") - print("Enter the base number: ") - x = enter_num() - print("Enter the exponent") - y = enter_num() - result = calc.exp(x, y) - return result - - elif Operation == 7: - print("Square Root") - print("Enter the number: ") - x = enter_num() - result = calc.square_root(x) - return result - - elif Operation == 8: - print("Inverse") - print("Enter the number: ") - x = enter_num() - result = calc.inv(x) - return result - -##TRIG FUNCTIONS -##must add statements for degrees/radians - - elif Operation == 9: - print("Sine") - print("Enter the number: ") - x = enter_num() - result = calc.sine(x) - return result - - - elif Operation == 10: - print("Cosine") - print("Enter the number: ") - x = enter_num() - result = calc.cosine(x) - return result - - - elif Operation == 11: - print("Tangent") - print("Enter the number: ") - x = enter_num() - result = calc.tangent(x) - return result - - - elif Operation == 12: - print("Inverse Sine") - print("Enter the number: ") - x = enter_num() - result = calc.invsine(x) - return result - - elif Operation == 13: - print("Inverse Cosine") - print("Enter the number: ") - x = enter_num() - result = calc.invcosine(x) - return result - - elif Operation == 14: - print("Inverse Tangent") - print("Enter the number: ") - x = enter_num() - result = calc.invtangent(x) - return result - -##MEMORY FUNCTIONS - - elif Operation == 15: - print("M+") - print("Enter the number: ") - memStore = float(input("Enter a value to store: ")) - print(memStore) - return memStore - - - elif Operation == 16: - print("MC") - if type(memStore) != None: - print(memStore) - - elif Operation == 17: - print("MCR") - store_choice = input("Do you want to clear memory? Y or N (case sensitive): ") - if store_choice == "Y": - memStore = 0 - else: - pass - print(memStore) - return memStore - - elif Operation == 18: - condi = False - print("Thank you for pushing my buttons!") - -##LOOPING OPERATIONS -###DEF FOR SECONDARY OPERATIONS - - -def choose_data_type(): - data_choice = int(input('Enter data type: 1. Decimal 2. Hexadecimal 3. Binary 4. Octal ')) - if data_choice == 1: - print(returned_result) - return returned_result - elif data_choice == 2: - print(hex(int(returned_result))) - return hex(int(returned_result)) - elif data_choice == 3: - print(bin(int(returned_result)).replace("0b", "")) - return bin(int(returned_result)).replace("0b", "") - elif data_choice == 4: - print(oct(int(returned_result))) - return oct(int(returned_result)) - - -def secondary_operation(): - print("1: Add 5: Square 9: M+") - print("2: Subtract 6: Square Root 10: MC") - print("3: Multiply 7: Exponent 11: MRC") - print("4: Divide 8: Inverse 12: Exit") - print("") - Operation = int(input('Choose an operation: ')) - - memStore = None - - if Operation == 1: - print("Add") - print("Enter number to add: ") - x = enter_num() - result = calc.add2(x) - return result - - elif Operation == 2: - print("Subtract") - print("Enter the number to subtract: ") - x = enter_num() - result = calc.subtract2(x) - return result - - elif Operation == 3: - print("Multiply") - print("Enter the second number: ") - x = enter_num() - result = calc.multiply2(x) - return result - - elif Operation == 4: - print("Divide") - print("Enter the second number: ") - x = enter_num() - result = calc.divide2(x) - return result - - elif Operation == 5: - print("Square") - result = square2(returned_result) - return result - - elif Operation == 6: - print("Exponent") - print("Enter the exponent: ") - x = enter_num() - result = calc.exp2(x) - return result - - elif Operation == 7: - print("Square Root") - result = calc.square_root2(returned_result) - return result - - elif Operation == 8: - print("Inverse") - result = inv2(returned_result) - return result - - elif Operation == 9: - memStore = returned_result - print(memStore) - return memStore - - elif Operation == 10: - if type(memStore) != None: - print(memStore) - else: - print('Empty') - - elif Operation == 11: - store_choice = input("Do you want to clear memory? Y or N (case sensitive): ") - if store_choice == "Y": - memStore = 0 - else: - pass - print(memStore) - return memStore - - elif Operation == 12: - condi = False - print('Goodbye!') -###################################################################### -## on screen ## - - -print("Welcome to our Calculator!") -print("How can we help you?") -print("") - - -condi = True -while condi: - returned_result = screen_options() - print(f"Result: {returned_result}") - choose_data_type() - print("") - cont = input("Continue with current value? Y or N (case sensitive): ") - print('') - if cont == "Y": - condi2 = True - while condi2: - returned_result = secondary_operation() - print(f"Result: {returned_result}") - choose_data_type() - print("") - cont2 = input("Continue with current value? Y or N (case sensitive): ") - print("") - if cont2 == "Y": - condi2 = True - else: - break \ No newline at end of file From c5195227d4d337a5276c0533cd51b3b97ba537fa Mon Sep 17 00:00:00 2001 From: Drake Dwornik Date: Sun, 31 Oct 2021 13:28:33 -0400 Subject: [PATCH 21/44] added state --- state.py | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 state.py diff --git a/state.py b/state.py new file mode 100644 index 0000000..4691ea1 --- /dev/null +++ b/state.py @@ -0,0 +1,5 @@ +class State: + def __init__(self): + degrees = True + display_mode = "decimal" + result = "" From 1ceaa211f25bc9d9c841975a3ad848522ecc61e4 Mon Sep 17 00:00:00 2001 From: Roethel Christine Date: Sun, 31 Oct 2021 16:26:59 -0400 Subject: [PATCH 22/44] added degrees and radians --- main_app.py | 97 +++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 71 insertions(+), 26 deletions(-) diff --git a/main_app.py b/main_app.py index f8c9b4d..1e3bbbf 100644 --- a/main_app.py +++ b/main_app.py @@ -4,6 +4,7 @@ calc=Calculator() + def enter_num(): try: num1 = float(input()) @@ -11,6 +12,7 @@ def enter_num(): except: calc.err() +##Calculator Options def screen_options(): print("1: Add 8: Inverse 15: M+") @@ -32,7 +34,7 @@ def screen_options(): x = enter_num() print("Enter the second number: ") y = enter_num() - result = calc.add(x, y) + result = calc.add(x ,y) return result elif Operation == 2: @@ -97,49 +99,92 @@ def screen_options(): return result ##TRIG FUNCTIONS -##must add statements for degrees/radians + ##updated with statements for degrees and radians elif Operation == 9: print("Sine") - print("Enter the number: ") - x = enter_num() - result = calc.sine(x) - return result + raddeg = int(input("For Radians: Enter 1; For Degrees: Enter 2: ")) + if raddeg == 1: + print("Enter an angle in Radians to find Sine: ") + x = enter_num() + result = calc.sine(x) + return result + elif raddeg == 2: + print("Enter an angle in Degrees to find Sine: ") + x = enter_num() + result = calc.sine(math.degrees(x)) + return result + elif Operation == 10: print("Cosine") - print("Enter the number: ") - x = enter_num() - result = calc.cosine(x) - return result + raddeg = int(input("For Radians: Enter 1; For Degrees: Enter 2: ")) + if raddeg == 1: + print("Enter an angle in Radians to find Cosine: ") + x = enter_num() + result = calc.cosine(x) + return result + elif raddeg == 2: + print("Enter an angle in Degrees to find Cosine: ") + x = enter_num() + result = calc.cosine(math.degrees(x)) + return result elif Operation == 11: print("Tangent") - print("Enter the number: ") - x = enter_num() - result = calc.tangent(x) - return result + raddeg = int(input("For Radians: Enter 1; For Degrees: Enter 2: ")) + if raddeg == 1: + print("Enter an angle in Radians to find Tangent: ") + x = enter_num() + result = calc.tangent(x) + return result + elif raddeg == 2: + print("Enter an angle in Degrees to find Tangent: ") + x = enter_num() + result = calc.tangent(math.degrees(x)) + return result elif Operation == 12: print("Inverse Sine") - print("Enter the number: ") - x = enter_num() - result = calc.invsine(x) - return result + raddeg = int(input("For Radians: Enter 1; For Degrees: Enter 2: ")) + if raddeg == 1: + print("Enter an angle in Radians to find Inverse Sine: ") + x = enter_num() + result = calc.inverse_sine(x) + return result + elif raddeg == 2: + print("Enter an angle in Degrees to find Inverse Sine: ") + x = enter_num() + result = calc.inverse_sine(math.degrees(x)) + return result elif Operation == 13: print("Inverse Cosine") - print("Enter the number: ") - x = enter_num() - result = calc.invcosine(x) - return result + raddeg = int(input("For Radians: Enter 1; For Degrees: Enter 2: ")) + if raddeg == 1: + print("Enter an angle in Radians to find Inverse Cosine: ") + x = enter_num() + result = calc.inverse_cosine(x) + return result + elif raddeg == 2: + print("Enter an angle in Degrees to find Inverse Cosine: ") + x = enter_num() + result = calc.inverse_cosine(math.degrees(x)) + return result elif Operation == 14: print("Inverse Tangent") - print("Enter the number: ") - x = enter_num() - result = calc.invtangent(x) - return result + raddeg = int(input("For Radians: Enter 1; For Degrees: Enter 2: ")) + if raddeg == 1: + print("Enter an angle in Radians to find Inverse Tangent: ") + x = enter_num() + result = calc.inverse_tangent(x) + return result + elif raddeg == 2: + print("Enter an angle in Degrees to find Inverse Tangent: ") + x = enter_num() + result = calc.inverse_tangent(math.degrees(x)) + return result ##MEMORY FUNCTIONS From 6847e655eba1ee9e815f9cafc47c2508556d8964 Mon Sep 17 00:00:00 2001 From: Roethel Christine Date: Sun, 31 Oct 2021 16:52:57 -0400 Subject: [PATCH 23/44] made small formatting changes --- calculator.py | 4 ++-- main_app.py | 23 ++++++++++------------- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/calculator.py b/calculator.py index dc88e06..0b6bd22 100644 --- a/calculator.py +++ b/calculator.py @@ -205,7 +205,7 @@ def add2(self, x): :param x: :return: """ - print( returned_result + x) + print(returned_result + x) return returned_result + x @@ -215,7 +215,7 @@ def subtract2(self, x): :param x: :return: """ - print( returned_result - x) + print(returned_result - x) return returned_result - x diff --git a/main_app.py b/main_app.py index 1e3bbbf..93fc18e 100644 --- a/main_app.py +++ b/main_app.py @@ -1,6 +1,5 @@ from calculator import Calculator import math -import decimal calc=Calculator() @@ -23,7 +22,6 @@ def screen_options(): print("6: Square Root 13: Inverse Consine") print("7: Exponent 14: Inverse Tangent") print("") - Operation = int(input('Choose an operation: (Select the number) ')) memStore = None @@ -39,18 +37,18 @@ def screen_options(): elif Operation == 2: print("Subtract") - print('Enter the first number: ') + print("Enter the first number: ") x = enter_num() - print('Enter the second number: ') + print("Enter the second number: ") y = enter_num() result = calc.subtract(x, y) return result elif Operation == 3: - print('Multiply') - print('Enter the first number: ') + print("Multiply") + print("Enter the first number: ") x = enter_num() - print('Enter the second number: ') + print("Enter the second number: ") y = enter_num() result = calc.multiply(x, y) return result @@ -190,8 +188,7 @@ def screen_options(): elif Operation == 15: print("M+") - print("Enter the number: ") - memStore = float(input("Enter a value to store: ")) + memStore = float(input("Enter a number to store: ")) print(memStore) return memStore @@ -219,7 +216,7 @@ def screen_options(): def choose_data_type(): - data_choice = int(input('Enter data type: 1. Decimal 2. Hexadecimal 3. Binary 4. Octal ')) + data_choice = int(input("Enter data type: 1. Decimal 2. Hexadecimal 3. Binary 4. Octal ")) if data_choice == 1: print(returned_result) return returned_result @@ -274,7 +271,7 @@ def secondary_operation(): elif Operation == 5: print("Square") - result = square2(returned_result) + result = calc.square2(returned_result) return result elif Operation == 6: @@ -291,7 +288,7 @@ def secondary_operation(): elif Operation == 8: print("Inverse") - result = inv2(returned_result) + result = calc.inv2(returned_result) return result elif Operation == 9: @@ -337,7 +334,7 @@ def main(): choose_data_type() print("") cont = capitalize(input("Do you want to clear memory? Y or N: ")) - print('') + print("") if cont == "Y": condi2 = True while condi2: From 4bfa7f937c41ecbadc01a175b10f89a9219c99d1 Mon Sep 17 00:00:00 2001 From: Roethel Christine Date: Sun, 31 Oct 2021 17:07:56 -0400 Subject: [PATCH 24/44] made more changes --- main_app.py | 69 +++++++++++++++++++++++++++-------------------------- 1 file changed, 35 insertions(+), 34 deletions(-) diff --git a/main_app.py b/main_app.py index 93fc18e..967897c 100644 --- a/main_app.py +++ b/main_app.py @@ -22,7 +22,7 @@ def screen_options(): print("6: Square Root 13: Inverse Consine") print("7: Exponent 14: Inverse Tangent") print("") - Operation = int(input('Choose an operation: (Select the number) ')) + Operation = int(input("Choose an operation: (Select the number) ")) memStore = None @@ -199,7 +199,7 @@ def screen_options(): elif Operation == 17: print("MCR") - store_choice = capitalize(input("Do you want to clear memory? Y or N: ")) + store_choice = (input("Do you want to clear memory? Y or N: ")).capitalize() if store_choice == "Y": memStore = 0 else: @@ -216,17 +216,17 @@ def screen_options(): def choose_data_type(): - data_choice = int(input("Enter data type: 1. Decimal 2. Hexadecimal 3. Binary 4. Octal ")) - if data_choice == 1: + type_choice = int(input("Enter data type: 1. Decimal 2. Hexadecimal 3. Binary 4. Octal ")) + if type_choice == 1: print(returned_result) return returned_result - elif data_choice == 2: + elif type_choice == 2: print(hex(int(returned_result))) return hex(int(returned_result)) - elif data_choice == 3: + elif type_choice == 3: print(bin(int(returned_result)).replace("0b", "")) return bin(int(returned_result)).replace("0b", "") - elif data_choice == 4: + elif type_choice == 4: print(oct(int(returned_result))) return oct(int(returned_result)) @@ -303,7 +303,7 @@ def secondary_operation(): print('Empty') elif Operation == 11: - store_choice = capitalize(input("Do you want to clear memory? Y or N: ")) + store_choice = (input("Do you want to clear memory? Y or N: ")).capitalize() if store_choice == "Y": memStore = 0 else: @@ -320,34 +320,35 @@ def secondary_operation(): ## on screen ## -def welcome(): - print("Welcome to our Calculator!") - print("How can we help you?") - print("") +#loop does not operate correctly while welcome and main are defined as functions, must keep open + +print("Welcome to our Calculator!") +print("How can we help you?") +print("") + -def main(): - condi = True - while condi: - returned_result = screen_options() - print(f"Result: {returned_result}") - choose_data_type() - print("") - cont = capitalize(input("Do you want to clear memory? Y or N: ")) - print("") - if cont == "Y": - condi2 = True - while condi2: - returned_result = secondary_operation() - print(f"Result: {returned_result}") - choose_data_type() - print("") - cont2 = capitalize(input("Do you want to clear memory? Y or N: ")) - print("") - if cont2 == "Y": - condi2 = True - else: - break +condi = True +while condi: + returned_result = screen_options() + print(f"Result: {returned_result}") + choose_data_type() + print("") + cont = (input("Do you want to clear memory? Y or N: ")).capitalize() + print("") + if cont == "Y": + condi2 = True + while condi2: + returned_result = secondary_operation() + print(f"Result: {returned_result}") + choose_data_type() + print("") + cont2 = (input("Do you want to clear memory? Y or N: ")).capitalize() + print("") + if cont2 == "Y": + condi2 = True + else: + break if __name__ == '__main__': From e21a7509883fb1903ba3fd4f6512f77f46a1332c Mon Sep 17 00:00:00 2001 From: Drake Dwornik Date: Sun, 31 Oct 2021 18:48:01 -0400 Subject: [PATCH 25/44] started using state for result --- calculator.py | 1 - main_app.py | 115 +++++++++++++++++++++++++++----------------------- state.py | 4 +- 3 files changed, 65 insertions(+), 55 deletions(-) diff --git a/calculator.py b/calculator.py index 0b6bd22..568a05b 100644 --- a/calculator.py +++ b/calculator.py @@ -11,7 +11,6 @@ def __init__(self): def err(self): self.error = True - self.degrees = True diff --git a/main_app.py b/main_app.py index 967897c..88036e0 100644 --- a/main_app.py +++ b/main_app.py @@ -1,7 +1,14 @@ from calculator import Calculator import math +from state import State + +calc = Calculator() +state = State() + + + + -calc=Calculator() def enter_num(): @@ -32,8 +39,8 @@ def screen_options(): x = enter_num() print("Enter the second number: ") y = enter_num() - result = calc.add(x ,y) - return result + state.result = calc.add(x ,y) + return state.result elif Operation == 2: print("Subtract") @@ -41,8 +48,8 @@ def screen_options(): x = enter_num() print("Enter the second number: ") y = enter_num() - result = calc.subtract(x, y) - return result + state.result = calc.subtract(x, y) + return state.result elif Operation == 3: print("Multiply") @@ -50,8 +57,8 @@ def screen_options(): x = enter_num() print("Enter the second number: ") y = enter_num() - result = calc.multiply(x, y) - return result + state.result = calc.multiply(x, y) + return state.result elif Operation == 4: print("Divide") @@ -63,15 +70,15 @@ def screen_options(): print("ERROR") return None else: - result = calc.divide(x, y) - return result + state.result = calc.divide(x, y) + return state.result elif Operation == 5: print("Square") print("Enter the number: ") base = enter_num() - result = square(base) - return result + state.result = square(base) + return state.result elif Operation == 6: print("Exponent") @@ -79,22 +86,22 @@ def screen_options(): x = enter_num() print("Enter the exponent") y = enter_num() - result = calc.exp(x, y) - return result + state.result = calc.exp(x, y) + return state.result elif Operation == 7: print("Square Root") print("Enter the number: ") x = enter_num() - result = calc.square_root(x) - return result + state.result = calc.square_root(x) + return state.result elif Operation == 8: print("Inverse") print("Enter the number: ") x = enter_num() - result = calc.inv(x) - return result + state.result = calc.inv(x) + return state.result ##TRIG FUNCTIONS ##updated with statements for degrees and radians @@ -105,13 +112,13 @@ def screen_options(): if raddeg == 1: print("Enter an angle in Radians to find Sine: ") x = enter_num() - result = calc.sine(x) - return result + state.result = calc.sine(x) + return state.result elif raddeg == 2: print("Enter an angle in Degrees to find Sine: ") x = enter_num() - result = calc.sine(math.degrees(x)) - return result + state.result = calc.sine(math.degrees(x)) + return state.result elif Operation == 10: @@ -120,13 +127,13 @@ def screen_options(): if raddeg == 1: print("Enter an angle in Radians to find Cosine: ") x = enter_num() - result = calc.cosine(x) - return result + state.result = calc.cosine(x) + return state.result elif raddeg == 2: print("Enter an angle in Degrees to find Cosine: ") x = enter_num() - result = calc.cosine(math.degrees(x)) - return result + state.result = calc.cosine(math.degrees(x)) + return state.result elif Operation == 11: print("Tangent") @@ -134,13 +141,13 @@ def screen_options(): if raddeg == 1: print("Enter an angle in Radians to find Tangent: ") x = enter_num() - result = calc.tangent(x) - return result + state.result = calc.tangent(x) + return state.result elif raddeg == 2: print("Enter an angle in Degrees to find Tangent: ") x = enter_num() - result = calc.tangent(math.degrees(x)) - return result + state.result = calc.tangent(math.degrees(x)) + return state.result elif Operation == 12: print("Inverse Sine") @@ -148,8 +155,8 @@ def screen_options(): if raddeg == 1: print("Enter an angle in Radians to find Inverse Sine: ") x = enter_num() - result = calc.inverse_sine(x) - return result + state.result = calc.inverse_sine(x) + return state.result elif raddeg == 2: print("Enter an angle in Degrees to find Inverse Sine: ") x = enter_num() @@ -162,13 +169,13 @@ def screen_options(): if raddeg == 1: print("Enter an angle in Radians to find Inverse Cosine: ") x = enter_num() - result = calc.inverse_cosine(x) - return result + state.result = calc.inverse_cosine(x) + return state.result elif raddeg == 2: print("Enter an angle in Degrees to find Inverse Cosine: ") x = enter_num() - result = calc.inverse_cosine(math.degrees(x)) - return result + state.result = calc.inverse_cosine(math.degrees(x)) + return state.result elif Operation == 14: print("Inverse Tangent") @@ -181,8 +188,8 @@ def screen_options(): elif raddeg == 2: print("Enter an angle in Degrees to find Inverse Tangent: ") x = enter_num() - result = calc.inverse_tangent(math.degrees(x)) - return result + state.result = calc.inverse_tangent(math.degrees(x)) + return state.result ##MEMORY FUNCTIONS @@ -245,51 +252,51 @@ def secondary_operation(): print("Add") print("Enter number to add: ") x = enter_num() - result = calc.add2(x) - return result + state.result = calc.add2(x) + return state.result elif Operation == 2: print("Subtract") print("Enter the number to subtract: ") x = enter_num() - result = calc.subtract2(x) - return result + state.result = calc.subtract2(x) + return state.result elif Operation == 3: print("Multiply") print("Enter the second number: ") x = enter_num() - result = calc.multiply2(x) - return result + state.result = calc.multiply2(x) + return state.result elif Operation == 4: print("Divide") print("Enter the second number: ") x = enter_num() - result = calc.divide2(x) - return result + state.result = calc.divide2(x) + return state.result elif Operation == 5: print("Square") - result = calc.square2(returned_result) - return result + state.result = calc.square2(returned_result) + return state.result elif Operation == 6: print("Exponent") print("Enter the exponent: ") x = enter_num() - result = calc.exp2(x) - return result + state.result = calc.exp2(x) + return state.result elif Operation == 7: print("Square Root") - result = calc.square_root2(returned_result) - return result + state.result = calc.square_root2(returned_result) + return state.result elif Operation == 8: print("Inverse") - result = calc.inv2(returned_result) - return result + state.result = calc.inv2(returned_result) + return state.result elif Operation == 9: memStore = returned_result @@ -351,7 +358,9 @@ def secondary_operation(): break + if __name__ == '__main__': + main() welcome() diff --git a/state.py b/state.py index 4691ea1..2cae312 100644 --- a/state.py +++ b/state.py @@ -1,5 +1,7 @@ class State: def __init__(self): + error = False + result = 0 degrees = True display_mode = "decimal" - result = "" + stored_number = 0 From 04409ceabe55e881a5021c21335d4711910c7dc2 Mon Sep 17 00:00:00 2001 From: Drake Dwornik Date: Sun, 31 Oct 2021 19:12:37 -0400 Subject: [PATCH 26/44] converted memstore to state object --- main_app.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/main_app.py b/main_app.py index 88036e0..2a93dce 100644 --- a/main_app.py +++ b/main_app.py @@ -179,11 +179,11 @@ def screen_options(): elif Operation == 14: print("Inverse Tangent") - raddeg = int(input("For Radians: Enter 1; For Degrees: Enter 2: ")) + raddeg = state.degrees if raddeg == 1: print("Enter an angle in Radians to find Inverse Tangent: ") x = enter_num() - result = calc.inverse_tangent(x) + result = calc.inverse_tangent(state.result) return result elif raddeg == 2: print("Enter an angle in Degrees to find Inverse Tangent: ") @@ -195,24 +195,24 @@ def screen_options(): elif Operation == 15: print("M+") - memStore = float(input("Enter a number to store: ")) - print(memStore) - return memStore + state.stored_number = float(input("Enter a number to store: ")) + print(state.stored_number) + return state.stored_number elif Operation == 16: print("MC") - if type(memStore) != None: - print(memStore) + if type(state.stored_number) != None: + print(state.stored_number) elif Operation == 17: print("MCR") store_choice = (input("Do you want to clear memory? Y or N: ")).capitalize() if store_choice == "Y": - memStore = 0 + state.stored_number= 0 else: pass - print(memStore) - return memStore + print(state.stored_number) + return state.stored_number elif Operation == 18: condi = False From 7000e5fbf1d20bbc236e8ab3b1622aa40b2ee1c8 Mon Sep 17 00:00:00 2001 From: DrakeDwornik Date: Sun, 31 Oct 2021 19:16:26 -0400 Subject: [PATCH 27/44] Create test --- test | 1 + 1 file changed, 1 insertion(+) create mode 100644 test diff --git a/test b/test new file mode 100644 index 0000000..eb86cbc --- /dev/null +++ b/test @@ -0,0 +1 @@ +testing pull From 3b9422a9fb182a97410721c2e92b76b2ff538c19 Mon Sep 17 00:00:00 2001 From: Drake Dwornik Date: Sun, 31 Oct 2021 19:18:49 -0400 Subject: [PATCH 28/44] deleted test file --- test | 1 - 1 file changed, 1 deletion(-) delete mode 100644 test diff --git a/test b/test deleted file mode 100644 index eb86cbc..0000000 --- a/test +++ /dev/null @@ -1 +0,0 @@ -testing pull From edc7b56959bbf32655db8fb8ad8517e92a14ecd6 Mon Sep 17 00:00:00 2001 From: Roethel Christine Date: Sun, 31 Oct 2021 20:20:00 -0400 Subject: [PATCH 29/44] made more changes2 --- main_app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main_app.py b/main_app.py index 2a93dce..bf8fb2a 100644 --- a/main_app.py +++ b/main_app.py @@ -341,7 +341,7 @@ def secondary_operation(): print(f"Result: {returned_result}") choose_data_type() print("") - cont = (input("Do you want to clear memory? Y or N: ")).capitalize() + cont = (input("Do you continue with this number? Y or N: ")).capitalize() print("") if cont == "Y": condi2 = True From a7cf9a2b0568dadb916291e006ed3ab162224440 Mon Sep 17 00:00:00 2001 From: Roethel Christine Date: Sun, 31 Oct 2021 20:40:14 -0400 Subject: [PATCH 30/44] changes with drake --- calculator.py | 21 ++++--- main_app.py | 155 +++++++++++++++++++++++++------------------------- 2 files changed, 89 insertions(+), 87 deletions(-) diff --git a/calculator.py b/calculator.py index 568a05b..c5fb457 100644 --- a/calculator.py +++ b/calculator.py @@ -6,7 +6,10 @@ class Calculator: def __init__(self): error = False - value = 0 + result = 0 + degrees = True + display_mode = "decimal" + stored_number = 0 def err(self): self.error = True @@ -204,8 +207,8 @@ def add2(self, x): :param x: :return: """ - print(returned_result + x) - return returned_result + x + print(self.result + x) + return self.result + x def subtract2(self, x): @@ -214,8 +217,8 @@ def subtract2(self, x): :param x: :return: """ - print(returned_result - x) - return returned_result - x + print(self.result - x) + return self.result - x def multiply2(self, x): @@ -224,8 +227,8 @@ def multiply2(self, x): :param x: :return: """ - print( returned_result * x) - return returned_result * x + print( self.result * x) + return self.result * x def divide2(self, x): @@ -234,6 +237,6 @@ def divide2(self, x): :param x: :return: """ - print( returned_result / x) - return returned_result / x + print( self.result / x) + return self.result / x diff --git a/main_app.py b/main_app.py index bf8fb2a..9ccaf16 100644 --- a/main_app.py +++ b/main_app.py @@ -1,9 +1,8 @@ from calculator import Calculator import math -from state import State calc = Calculator() -state = State() + @@ -39,8 +38,8 @@ def screen_options(): x = enter_num() print("Enter the second number: ") y = enter_num() - state.result = calc.add(x ,y) - return state.result + calc.result = calc.add(x ,y) + return calc.result elif Operation == 2: print("Subtract") @@ -48,8 +47,8 @@ def screen_options(): x = enter_num() print("Enter the second number: ") y = enter_num() - state.result = calc.subtract(x, y) - return state.result + calc.result = calc.subtract(x, y) + return calc.result elif Operation == 3: print("Multiply") @@ -57,8 +56,8 @@ def screen_options(): x = enter_num() print("Enter the second number: ") y = enter_num() - state.result = calc.multiply(x, y) - return state.result + calc.result = calc.multiply(x, y) + return calc.result elif Operation == 4: print("Divide") @@ -70,15 +69,15 @@ def screen_options(): print("ERROR") return None else: - state.result = calc.divide(x, y) - return state.result + calc.result = calc.divide(x, y) + return calc.result elif Operation == 5: print("Square") print("Enter the number: ") base = enter_num() - state.result = square(base) - return state.result + calc.result = square(base) + return calc.result elif Operation == 6: print("Exponent") @@ -86,25 +85,25 @@ def screen_options(): x = enter_num() print("Enter the exponent") y = enter_num() - state.result = calc.exp(x, y) - return state.result + calc.result = calc.exp(x, y) + return calc.result elif Operation == 7: print("Square Root") print("Enter the number: ") x = enter_num() - state.result = calc.square_root(x) - return state.result + calc.result = calc.square_root(x) + return calc.result elif Operation == 8: print("Inverse") print("Enter the number: ") x = enter_num() - state.result = calc.inv(x) - return state.result + calc.result = calc.inv(x) + return calc.result ##TRIG FUNCTIONS - ##updated with statements for degrees and radians + ##updated with calcments for degrees and radians elif Operation == 9: print("Sine") @@ -112,13 +111,13 @@ def screen_options(): if raddeg == 1: print("Enter an angle in Radians to find Sine: ") x = enter_num() - state.result = calc.sine(x) - return state.result + calc.result = calc.sine(x) + return calc.result elif raddeg == 2: print("Enter an angle in Degrees to find Sine: ") x = enter_num() - state.result = calc.sine(math.degrees(x)) - return state.result + calc.result = calc.sine(math.degrees(x)) + return calc.result elif Operation == 10: @@ -127,13 +126,13 @@ def screen_options(): if raddeg == 1: print("Enter an angle in Radians to find Cosine: ") x = enter_num() - state.result = calc.cosine(x) - return state.result + calc.result = calc.cosine(x) + return calc.result elif raddeg == 2: print("Enter an angle in Degrees to find Cosine: ") x = enter_num() - state.result = calc.cosine(math.degrees(x)) - return state.result + calc.result = calc.cosine(math.degrees(x)) + return calc.result elif Operation == 11: print("Tangent") @@ -141,13 +140,13 @@ def screen_options(): if raddeg == 1: print("Enter an angle in Radians to find Tangent: ") x = enter_num() - state.result = calc.tangent(x) - return state.result + calc.result = calc.tangent(x) + return calc.result elif raddeg == 2: print("Enter an angle in Degrees to find Tangent: ") x = enter_num() - state.result = calc.tangent(math.degrees(x)) - return state.result + calc.result = calc.tangent(math.degrees(x)) + return calc.result elif Operation == 12: print("Inverse Sine") @@ -155,8 +154,8 @@ def screen_options(): if raddeg == 1: print("Enter an angle in Radians to find Inverse Sine: ") x = enter_num() - state.result = calc.inverse_sine(x) - return state.result + calc.result = calc.inverse_sine(x) + return calc.result elif raddeg == 2: print("Enter an angle in Degrees to find Inverse Sine: ") x = enter_num() @@ -169,50 +168,50 @@ def screen_options(): if raddeg == 1: print("Enter an angle in Radians to find Inverse Cosine: ") x = enter_num() - state.result = calc.inverse_cosine(x) - return state.result + calc.result = calc.inverse_cosine(x) + return calc.result elif raddeg == 2: print("Enter an angle in Degrees to find Inverse Cosine: ") x = enter_num() - state.result = calc.inverse_cosine(math.degrees(x)) - return state.result + calc.result = calc.inverse_cosine(math.degrees(x)) + return calc.result elif Operation == 14: print("Inverse Tangent") - raddeg = state.degrees + raddeg = calc.degrees if raddeg == 1: print("Enter an angle in Radians to find Inverse Tangent: ") x = enter_num() - result = calc.inverse_tangent(state.result) + result = calc.inverse_tangent(calc.result) return result elif raddeg == 2: print("Enter an angle in Degrees to find Inverse Tangent: ") x = enter_num() - state.result = calc.inverse_tangent(math.degrees(x)) - return state.result + calc.result = calc.inverse_tangent(math.degrees(x)) + return calc.result ##MEMORY FUNCTIONS elif Operation == 15: print("M+") - state.stored_number = float(input("Enter a number to store: ")) - print(state.stored_number) - return state.stored_number + calc.stored_number = float(input("Enter a number to store: ")) + print(calc.stored_number) + return calc.stored_number elif Operation == 16: print("MC") - if type(state.stored_number) != None: - print(state.stored_number) + if type(calc.stored_number) != None: + print(calc.stored_number) elif Operation == 17: print("MCR") store_choice = (input("Do you want to clear memory? Y or N: ")).capitalize() if store_choice == "Y": - state.stored_number= 0 + calc.stored_number= 0 else: pass - print(state.stored_number) - return state.stored_number + print(calc.stored_number) + return calc.stored_number elif Operation == 18: condi = False @@ -225,17 +224,17 @@ def screen_options(): def choose_data_type(): type_choice = int(input("Enter data type: 1. Decimal 2. Hexadecimal 3. Binary 4. Octal ")) if type_choice == 1: - print(returned_result) - return returned_result + print(calc.result) + return (calc.result) elif type_choice == 2: - print(hex(int(returned_result))) - return hex(int(returned_result)) + print(hex(int(calc.result))) + return hex(int(calc.result)) elif type_choice == 3: - print(bin(int(returned_result)).replace("0b", "")) - return bin(int(returned_result)).replace("0b", "") + print(bin(int(calc.result)).replace("0b", "")) + return bin(int(calc.result)).replace("0b", "") elif type_choice == 4: - print(oct(int(returned_result))) - return oct(int(returned_result)) + print(oct(int(calc.resultt))) + return oct(int(calc.result)) def secondary_operation(): @@ -252,54 +251,54 @@ def secondary_operation(): print("Add") print("Enter number to add: ") x = enter_num() - state.result = calc.add2(x) - return state.result + calc.result = calc.add2(x) + return calc.result elif Operation == 2: print("Subtract") print("Enter the number to subtract: ") x = enter_num() - state.result = calc.subtract2(x) - return state.result + calc.result = calc.subtract2(x) + return calc.result elif Operation == 3: print("Multiply") print("Enter the second number: ") x = enter_num() - state.result = calc.multiply2(x) - return state.result + calc.result = calc.multiply2(x) + return calc.result elif Operation == 4: print("Divide") print("Enter the second number: ") x = enter_num() - state.result = calc.divide2(x) - return state.result + calc.result = calc.divide2(x) + return calc.result elif Operation == 5: print("Square") - state.result = calc.square2(returned_result) - return state.result + calc.result = calc.square2(calc.result) + return calc.result elif Operation == 6: print("Exponent") print("Enter the exponent: ") x = enter_num() - state.result = calc.exp2(x) - return state.result + calc.result = calc.exp2(x) + return calc.result elif Operation == 7: print("Square Root") - state.result = calc.square_root2(returned_result) - return state.result + calc.result = calc.square_root2(calc.result) + return calc.result elif Operation == 8: print("Inverse") - state.result = calc.inv2(returned_result) - return state.result + calc.result = calc.inv2(calc.result) + return calc.result elif Operation == 9: - memStore = returned_result + memStore = calc.result print(memStore) return memStore @@ -337,8 +336,8 @@ def secondary_operation(): condi = True while condi: - returned_result = screen_options() - print(f"Result: {returned_result}") + calc.result = screen_options() + print(f"Result: {calc.result}") choose_data_type() print("") cont = (input("Do you continue with this number? Y or N: ")).capitalize() @@ -346,8 +345,8 @@ def secondary_operation(): if cont == "Y": condi2 = True while condi2: - returned_result = secondary_operation() - print(f"Result: {returned_result}") + calc.result = secondary_operation() + print(f"Result: {calc.result}") choose_data_type() print("") cont2 = (input("Do you want to clear memory? Y or N: ")).capitalize() From 0f86c72bc3cf2ac4b6e3ae3c0f777d2d8fcecda7 Mon Sep 17 00:00:00 2001 From: Roethel Christine Date: Sun, 31 Oct 2021 20:42:16 -0400 Subject: [PATCH 31/44] changes with drake2 --- main_app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main_app.py b/main_app.py index 9ccaf16..8ce7d2c 100644 --- a/main_app.py +++ b/main_app.py @@ -349,7 +349,7 @@ def secondary_operation(): print(f"Result: {calc.result}") choose_data_type() print("") - cont2 = (input("Do you want to clear memory? Y or N: ")).capitalize() + cont2 = (input("Do you continue with this number? Y or N: ")).capitalize() print("") if cont2 == "Y": condi2 = True From a7d451edcd77c63fc87082b26ebe67a515069c5f Mon Sep 17 00:00:00 2001 From: Roethel Christine Date: Sun, 31 Oct 2021 21:06:08 -0400 Subject: [PATCH 32/44] changes with drake3 --- calculator.py | 10 +++++----- main_app.py | 32 +++++++++++++++++++------------- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/calculator.py b/calculator.py index c5fb457..a61c463 100644 --- a/calculator.py +++ b/calculator.py @@ -5,11 +5,11 @@ class Calculator: def __init__(self): - error = False - result = 0 - degrees = True - display_mode = "decimal" - stored_number = 0 + self.error = False + self.result = 0 + self.degrees = True + self.display_mode = "decimal" + self.stored_number = 0 def err(self): self.error = True diff --git a/main_app.py b/main_app.py index 8ce7d2c..cd32a81 100644 --- a/main_app.py +++ b/main_app.py @@ -23,8 +23,8 @@ def screen_options(): print("1: Add 8: Inverse 15: M+") print("2: Subtract 9: Sine 16: MC") print("3: Multiply 10: Cosine 17: MRC") - print("4: Divide 11: Tangent 18: Exit") - print("5: Square 12: Inverse Sine") + print("4: Divide 11: Tangent 18: Swap") + print("5: Square 12: Inverse Sine 19: Exit") print("6: Square Root 13: Inverse Consine") print("7: Exponent 14: Inverse Tangent") print("") @@ -107,17 +107,13 @@ def screen_options(): elif Operation == 9: print("Sine") - raddeg = int(input("For Radians: Enter 1; For Degrees: Enter 2: ")) - if raddeg == 1: - print("Enter an angle in Radians to find Sine: ") - x = enter_num() - calc.result = calc.sine(x) - return calc.result - elif raddeg == 2: - print("Enter an angle in Degrees to find Sine: ") - x = enter_num() - calc.result = calc.sine(math.degrees(x)) - return calc.result + if calc.degrees: + print("Enter a number in degrees to find Sine: ") + else: + print("Enter a number in radians to find Sine: ") + x = enter_num() + calc.result = calc.sin(x) + return calc.result elif Operation == 10: @@ -134,6 +130,7 @@ def screen_options(): calc.result = calc.cosine(math.degrees(x)) return calc.result + elif Operation == 11: print("Tangent") raddeg = int(input("For Radians: Enter 1; For Degrees: Enter 2: ")) @@ -148,6 +145,7 @@ def screen_options(): calc.result = calc.tangent(math.degrees(x)) return calc.result + elif Operation == 12: print("Inverse Sine") raddeg = int(input("For Radians: Enter 1; For Degrees: Enter 2: ")) @@ -214,6 +212,14 @@ def screen_options(): return calc.stored_number elif Operation == 18: + calc.deg_rad_swap() + if calc.degrees: + return ("You are in degrees mode") + else: + return ("You are in radiants mode") + + + elif Operation == 19: condi = False print("Thank you for pushing my buttons!") From ad9d6f454d6d25a4b2d885d8eb336744ba846ef5 Mon Sep 17 00:00:00 2001 From: Roethel Christine Date: Sun, 31 Oct 2021 21:22:55 -0400 Subject: [PATCH 33/44] pi & eval in main --- main_app.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/main_app.py b/main_app.py index cd32a81..6f7ecf9 100644 --- a/main_app.py +++ b/main_app.py @@ -17,6 +17,8 @@ def enter_num(): except: calc.err() + + ##Calculator Options def screen_options(): @@ -24,9 +26,9 @@ def screen_options(): print("2: Subtract 9: Sine 16: MC") print("3: Multiply 10: Cosine 17: MRC") print("4: Divide 11: Tangent 18: Swap") - print("5: Square 12: Inverse Sine 19: Exit") - print("6: Square Root 13: Inverse Consine") - print("7: Exponent 14: Inverse Tangent") + print("5: Square 12: Inverse Sine 19: Pi") + print("6: Square Root 13: Inverse Consine 20: Evaluate") + print("7: Exponent 14: Inverse Tangent 21: Exit") print("") Operation = int(input("Choose an operation: (Select the number) ")) @@ -218,8 +220,16 @@ def screen_options(): else: return ("You are in radiants mode") - elif Operation == 19: + print("PI = ") + return 3.14159265359 + + elif Operation == 20: + print("Evaluate") + x = str(input("Enter what you would like evaluated: ")) + return calc.eval_function(x) + + elif Operation == 21: condi = False print("Thank you for pushing my buttons!") From 40d2f80c75f1b54eb591a7c572180faa28f3f94e Mon Sep 17 00:00:00 2001 From: Drake Dwornik Date: Sun, 31 Oct 2021 21:27:47 -0400 Subject: [PATCH 34/44] added eval to the calculator class --- calculator.py | 6 ++++++ temp_script.py | 0 2 files changed, 6 insertions(+) create mode 100644 temp_script.py diff --git a/calculator.py b/calculator.py index a61c463..6078d59 100644 --- a/calculator.py +++ b/calculator.py @@ -14,6 +14,12 @@ def __init__(self): def err(self): self.error = True + def eval_function(self, x: str): -> float + """ + evaluates x to return a result + """ + print(eval(x)) + return eval(x) diff --git a/temp_script.py b/temp_script.py new file mode 100644 index 0000000..e69de29 From 6d122f1e4c2aedc5ecbfb05a38c7801f20eb6dbf Mon Sep 17 00:00:00 2001 From: Drake Dwornik Date: Sun, 31 Oct 2021 21:47:05 -0400 Subject: [PATCH 35/44] git experiment --- calculator.py | 3 +-- empty_file | 0 main_app.py | 5 +++-- 3 files changed, 4 insertions(+), 4 deletions(-) create mode 100644 empty_file diff --git a/calculator.py b/calculator.py index 6078d59..0abf030 100644 --- a/calculator.py +++ b/calculator.py @@ -14,11 +14,10 @@ def __init__(self): def err(self): self.error = True - def eval_function(self, x: str): -> float + def eval_function(self, x: str) -> float: """ evaluates x to return a result """ - print(eval(x)) return eval(x) diff --git a/empty_file b/empty_file new file mode 100644 index 0000000..e69de29 diff --git a/main_app.py b/main_app.py index 6f7ecf9..9078d50 100644 --- a/main_app.py +++ b/main_app.py @@ -227,7 +227,8 @@ def screen_options(): elif Operation == 20: print("Evaluate") x = str(input("Enter what you would like evaluated: ")) - return calc.eval_function(x) + calc.result = calc.eval_function(x) + return calc.result elif Operation == 21: condi = False @@ -249,7 +250,7 @@ def choose_data_type(): print(bin(int(calc.result)).replace("0b", "")) return bin(int(calc.result)).replace("0b", "") elif type_choice == 4: - print(oct(int(calc.resultt))) + print(oct(int(calc.result))) return oct(int(calc.result)) From e072ca7f3ec10af82e9ec4cfa8e360b507ff67db Mon Sep 17 00:00:00 2001 From: Naicker Creason Date: Sun, 31 Oct 2021 22:07:45 -0400 Subject: [PATCH 36/44] I have made more changes --- calculator.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/calculator.py b/calculator.py index 39915df..589759c 100644 --- a/calculator.py +++ b/calculator.py @@ -243,10 +243,7 @@ def divide2(self, x): :return: """ - print( returned_result / x) - return returned_result / x - - print( self.result / x) + print(self.result / x) return self.result / x From 62bebd1092b9ccd0c57e9cf7b79a7321cb0eab6d Mon Sep 17 00:00:00 2001 From: Naicker Creason Date: Sun, 31 Oct 2021 23:04:46 -0400 Subject: [PATCH 37/44] fixed duplicate inverse functions --- calculator.py | 17 +---------------- main_app.py | 40 ++++++++++------------------------------ 2 files changed, 11 insertions(+), 46 deletions(-) diff --git a/calculator.py b/calculator.py index 589759c..53f7547 100644 --- a/calculator.py +++ b/calculator.py @@ -10,6 +10,7 @@ def __init__(self): self.degrees = True self.display_mode = "decimal" self.stored_number = 0 + self.exit = False def err(self): self.error = True @@ -119,23 +120,7 @@ def inv(self, x): self.err() return "Err" print(1 / x) - """ - FINDS THE SQUARE ROOT OF A NUMBER AND RETURNS RESULT - :param x: - :return: - """ - print( x ** (1 / 2)) - return x ** (1 / 2) - - def inverse(self, x): - """ - INVERSES A NUMBER AND RETURNS RESULT - :param x: - :return: - """ - print( 1 / x) - return 1 / x def deg_rad_swap(self): """ diff --git a/main_app.py b/main_app.py index 9078d50..3e4dffa 100644 --- a/main_app.py +++ b/main_app.py @@ -120,13 +120,9 @@ def screen_options(): elif Operation == 10: print("Cosine") - raddeg = int(input("For Radians: Enter 1; For Degrees: Enter 2: ")) - if raddeg == 1: + if calc.degrees: print("Enter an angle in Radians to find Cosine: ") - x = enter_num() - calc.result = calc.cosine(x) - return calc.result - elif raddeg == 2: + else: print("Enter an angle in Degrees to find Cosine: ") x = enter_num() calc.result = calc.cosine(math.degrees(x)) @@ -135,13 +131,9 @@ def screen_options(): elif Operation == 11: print("Tangent") - raddeg = int(input("For Radians: Enter 1; For Degrees: Enter 2: ")) - if raddeg == 1: + if calc.degrees: print("Enter an angle in Radians to find Tangent: ") - x = enter_num() - calc.result = calc.tangent(x) - return calc.result - elif raddeg == 2: + else: print("Enter an angle in Degrees to find Tangent: ") x = enter_num() calc.result = calc.tangent(math.degrees(x)) @@ -150,13 +142,9 @@ def screen_options(): elif Operation == 12: print("Inverse Sine") - raddeg = int(input("For Radians: Enter 1; For Degrees: Enter 2: ")) - if raddeg == 1: + if calc.degrees: print("Enter an angle in Radians to find Inverse Sine: ") - x = enter_num() - calc.result = calc.inverse_sine(x) - return calc.result - elif raddeg == 2: + else: print("Enter an angle in Degrees to find Inverse Sine: ") x = enter_num() result = calc.inverse_sine(math.degrees(x)) @@ -164,13 +152,9 @@ def screen_options(): elif Operation == 13: print("Inverse Cosine") - raddeg = int(input("For Radians: Enter 1; For Degrees: Enter 2: ")) - if raddeg == 1: + if calc.degrees: print("Enter an angle in Radians to find Inverse Cosine: ") - x = enter_num() - calc.result = calc.inverse_cosine(x) - return calc.result - elif raddeg == 2: + else: print("Enter an angle in Degrees to find Inverse Cosine: ") x = enter_num() calc.result = calc.inverse_cosine(math.degrees(x)) @@ -178,13 +162,9 @@ def screen_options(): elif Operation == 14: print("Inverse Tangent") - raddeg = calc.degrees - if raddeg == 1: + if calc.degrees: print("Enter an angle in Radians to find Inverse Tangent: ") - x = enter_num() - result = calc.inverse_tangent(calc.result) - return result - elif raddeg == 2: + else: print("Enter an angle in Degrees to find Inverse Tangent: ") x = enter_num() calc.result = calc.inverse_tangent(math.degrees(x)) From 39796f7afa7900688748416633b2eb8681a1a84f Mon Sep 17 00:00:00 2001 From: Naicker Creason Date: Sun, 31 Oct 2021 23:51:14 -0400 Subject: [PATCH 38/44] fixed math functions & removed extra print statements --- calculator.py | 30 ++++++++++++++++++++---------- main_app.py | 50 +++++++++++++++++++++++++------------------------- 2 files changed, 45 insertions(+), 35 deletions(-) diff --git a/calculator.py b/calculator.py index 53f7547..f44f435 100644 --- a/calculator.py +++ b/calculator.py @@ -146,8 +146,10 @@ def cosine(self, x): :return: """ if self.degrees: - x = math.radians(x) - return math.cos(x) + x = math.degrees(math.cos(x)) + else: + x = math.cos(x) + return x def tangent(self, x): """ @@ -156,8 +158,10 @@ def tangent(self, x): :return: """ if self.degrees: - x = math.radians(x) - return math.tan(x) + x = math.degrees(math.tan(x)) + else: + x = math.tan(x) + return x def inverse_sine(self, x): """ @@ -166,8 +170,10 @@ def inverse_sine(self, x): :return: """ if self.degrees: - x = math.radians(x) - return math.asin(x) + x = math.degrees(math.asin(x)) + else: + x = math.asin(x) + return x def inverse_cosine(self, x): """ @@ -176,8 +182,10 @@ def inverse_cosine(self, x): :return: """ if self.degrees: - x = math.radians(x) - return math.acos(x) + x = math.degrees(math.acos(x)) + else: + x = math.acos(x) + return x def inverse_tangent(self, x): """ @@ -186,8 +194,10 @@ def inverse_tangent(self, x): :return: """ if self.degrees: - x = math.radians(x) - return math.atan(x) + x = math.degrees(math.atan(x)) + else: + x = math.atan(x) + return x ##SECONDARY FORMULAS diff --git a/main_app.py b/main_app.py index 3e4dffa..b3f7c6a 100644 --- a/main_app.py +++ b/main_app.py @@ -121,54 +121,54 @@ def screen_options(): elif Operation == 10: print("Cosine") if calc.degrees: - print("Enter an angle in Radians to find Cosine: ") + print("Enter an angle in degrees to find Cosine: ") else: - print("Enter an angle in Degrees to find Cosine: ") - x = enter_num() - calc.result = calc.cosine(math.degrees(x)) - return calc.result + print("Enter an angle in radians to find Cosine: ") + x = enter_num() + calc.result = calc.cosine(x) + return calc.result elif Operation == 11: print("Tangent") if calc.degrees: - print("Enter an angle in Radians to find Tangent: ") + print("Enter an angle in degrees to find Tangent: ") else: - print("Enter an angle in Degrees to find Tangent: ") - x = enter_num() - calc.result = calc.tangent(math.degrees(x)) - return calc.result + print("Enter an angle in radians to find Tangent: ") + x = enter_num() + calc.result = calc.tangent(x) + return calc.result elif Operation == 12: print("Inverse Sine") if calc.degrees: - print("Enter an angle in Radians to find Inverse Sine: ") + print("Enter a number to find the arc sine in degrees: ") else: - print("Enter an angle in Degrees to find Inverse Sine: ") - x = enter_num() - result = calc.inverse_sine(math.degrees(x)) - return result + print("Enter a number to find the arc sine in radians: ") + x = enter_num() + result = calc.inverse_sine(x) + return result elif Operation == 13: print("Inverse Cosine") if calc.degrees: - print("Enter an angle in Radians to find Inverse Cosine: ") + print("Enter an angle in degrees to find Inverse Cosine: ") else: - print("Enter an angle in Degrees to find Inverse Cosine: ") - x = enter_num() - calc.result = calc.inverse_cosine(math.degrees(x)) - return calc.result + print("Enter an angle in radians to find Inverse Cosine: ") + x = enter_num() + calc.result = calc.inverse_cosine(x) + return calc.result elif Operation == 14: print("Inverse Tangent") if calc.degrees: - print("Enter an angle in Radians to find Inverse Tangent: ") + print("Enter an angle in degrees to find Inverse Tangent: ") else: - print("Enter an angle in Degrees to find Inverse Tangent: ") - x = enter_num() - calc.result = calc.inverse_tangent(math.degrees(x)) - return calc.result + print("Enter an angle in radians to find Inverse Tangent: ") + x = enter_num() + calc.result = calc.inverse_tangent(x) + return calc.result ##MEMORY FUNCTIONS From 7730e6daa4dac66f488ee599c5a6044224c48564 Mon Sep 17 00:00:00 2001 From: Naicker Creason Date: Mon, 1 Nov 2021 00:09:19 -0400 Subject: [PATCH 39/44] removed redundant print statement --- calculator.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/calculator.py b/calculator.py index f44f435..2e3bd30 100644 --- a/calculator.py +++ b/calculator.py @@ -30,7 +30,6 @@ def add(self, a, b): :param b: :return: """ - print( a + b) return a + b @@ -41,7 +40,6 @@ def subtract(self, x, y): :param y: :return: """ - print( x - y) return x - y @@ -52,7 +50,6 @@ def multiply(self, x, y): :param y: :return: """ - print( x * y) return y * x @@ -79,7 +76,6 @@ def square(self, base): :param base: :return: """ - print( base ** 2) return base ** 2 @@ -90,7 +86,6 @@ def exp(self, x, y): :param y: :return: """ - print( x ** y) return x ** y From 4d48ba0851589af42df838d42eb223d49be84907 Mon Sep 17 00:00:00 2001 From: Drake Dwornik Date: Mon, 1 Nov 2021 07:23:20 -0400 Subject: [PATCH 40/44] Finished adding tests and cleaning failures --- calculator.py | 80 ++++++++++++++++++++------------- main_app.py | 2 +- test_calculator.py | 108 ++++++++++++++++++++++++++++++++------------- 3 files changed, 129 insertions(+), 61 deletions(-) diff --git a/calculator.py b/calculator.py index 2e3bd30..516ca88 100644 --- a/calculator.py +++ b/calculator.py @@ -15,11 +15,15 @@ def __init__(self): def err(self): self.error = True - def eval_function(self, x: str) -> float: + def eval_function(self, x: str): """ evaluates x to return a result """ - return eval(x) + try: + result = eval(x) + return result + except: + return "Err" @@ -103,7 +107,7 @@ def square_root(self, x): return math.sqrt(x) - def inv(self, x): + def invert(self, x): """ INVERSES A NUMBER AND RETURNS RESULT :param x: @@ -111,10 +115,10 @@ def inv(self, x): """ try: result = 1/x + return result except: self.err() return "Err" - print(1 / x) def deg_rad_swap(self): @@ -130,9 +134,12 @@ def sin(self, x): :param x: :return: """ - if self.degrees: - x = math.radians(x) - return math.sin(x) + try: + if self.degrees: + x = math.radians(x) + return math.sin(x) + except: + return "Err" def cosine(self, x): """ @@ -140,11 +147,13 @@ def cosine(self, x): :param x: :return: """ - if self.degrees: - x = math.degrees(math.cos(x)) - else: + try: + if self.degrees: + x = math.radians(x) x = math.cos(x) - return x + return x + except: + return "Err" def tangent(self, x): """ @@ -152,11 +161,13 @@ def tangent(self, x): :param x: :return: """ - if self.degrees: - x = math.degrees(math.tan(x)) - else: + try: + if self.degrees: + x = math.radians(x) x = math.tan(x) - return x + return x + except: + return "Err" def inverse_sine(self, x): """ @@ -164,11 +175,14 @@ def inverse_sine(self, x): :param x: :return: """ - if self.degrees: - x = math.degrees(math.asin(x)) - else: - x = math.asin(x) - return x + try: + if self.degrees: + x = math.degrees(math.asin(x)) + else: + x = math.asin(x) + return x + except: + return "Err" def inverse_cosine(self, x): """ @@ -176,11 +190,14 @@ def inverse_cosine(self, x): :param x: :return: """ - if self.degrees: - x = math.degrees(math.acos(x)) - else: - x = math.acos(x) - return x + try: + if self.degrees: + x = math.degrees(math.acos(x)) + else: + x = math.acos(x) + return x + except: + return "Err" def inverse_tangent(self, x): """ @@ -188,11 +205,14 @@ def inverse_tangent(self, x): :param x: :return: """ - if self.degrees: - x = math.degrees(math.atan(x)) - else: - x = math.atan(x) - return x + try: + if self.degrees: + x = math.degrees(math.atan(x)) + else: + x = math.atan(x) + return x + except: + return "Err" ##SECONDARY FORMULAS diff --git a/main_app.py b/main_app.py index b3f7c6a..8101aa0 100644 --- a/main_app.py +++ b/main_app.py @@ -101,7 +101,7 @@ def screen_options(): print("Inverse") print("Enter the number: ") x = enter_num() - calc.result = calc.inv(x) + calc.result = calc.invert(x) return calc.result ##TRIG FUNCTIONS diff --git a/test_calculator.py b/test_calculator.py index d099528..c13a5ff 100644 --- a/test_calculator.py +++ b/test_calculator.py @@ -1,55 +1,63 @@ import unittest +import math from calculator import Calculator - -def runTest(self, prompt_str, expected_out): - with patch('builtins.input', return_value=prompt_str), patch('sys.stdout', new=StringIO()) as fake_out: - answer() - self.assertEqual(enter_num(), expected_out) - - class TestStringMethods(unittest.TestCase): def test_add(self): c = Calculator() self.assertEqual(c.add(3, 4), 7) - self.assertEqual(c.add(-3,-4), -7) - self.assertTrue(c.add(3,-4), -1) + self.assertEqual(c.add(-3, -4), -7) + self.assertTrue(c.add(3, -4), -1) + + def test_eval_function(self): + c = Calculator() + self.assertEqual(c.eval_function("qw+2"), "Err") + self.assertEqual(c.eval_function("1 + 2"), 3) def test_subtract(self): c = Calculator() self.assertEqual(c.subtract(3, 4), -1) - self.assertEqual(c.subtract(-3,-4), 1) - self.assertTrue(c.subtract(3,-4), 7) + self.assertEqual(c.subtract(-3, -4), 1) + self.assertTrue(c.subtract(3, -4), 7) def test_multiply(self): c = Calculator() self.assertEqual(c.multiply(3, 4), 12) - self.assertEqual(c.multiply(-3,-4), 12) - self.assertTrue(c.multiply(3,-4), -12) + self.assertEqual(c.multiply(-3, -4), 12) + self.assertTrue(c.multiply(3, -4), -12) + def test_divide(self): c = Calculator() self.assertEqual(c.divide(3, 4), .75) - self.assertEqual(c.divide(-3,-4), .75) - self.assertEqual(c.divide(3,-4), -.75) - self.assertEqual(c.divide(3,0),"Err") + self.assertEqual(c.divide(-3, -4), .75) + self.assertEqual(c.divide(3, -4), -.75) + self.assertEqual(c.divide(3, 0), "Err") + def test_square(self): c = Calculator() self.assertEqual(c.square(3), 9) self.assertEqual(c.square(-4), 16) self.assertEqual(c.square(0), 0) + def test_exp(self): c = Calculator() self.assertEqual(c.exp(3, 4), 81) - self.assertEqual(c.exp(3, -4), (1/3)*(1/3)*(1/3)*(1/3)) - self.assertEqual(c.exp(-3, -4), (-(1/3))*(-(1/3))*(-(1/3))*(-(1/3))) + self.assertEqual(c.exp(3, -4), (1 / 3) * (1 / 3) * (1 / 3) * (1 / 3)) + self.assertEqual(c.exp(-3, -4), (-(1 / 3)) * (-(1 / 3)) * (-(1 / 3)) * (-(1 / 3))) self.assertEqual(c.exp(0, 0), 1) + def test_square_root(self): c = Calculator() self.assertEqual(c.square_root(-2), "Err") self.assertEqual(c.square_root(9), 3) - self.assertEqual(c.square_root(0),0) + self.assertEqual(c.square_root(0), 0) + + # def test_invert(self): + # c = Calculator() + # self.assertEqual(c.invert(2), 0.2) + # # self.assertEqual(c.inv(0),"Err") def test_add2(self): c = Calculator() @@ -67,25 +75,65 @@ def test_divide2(self): c = Calculator() self.assertEqual(c.add(5, 8), 13) - def test_inv(self): + def test_invert(self): c = Calculator() - self.assertEqual(c.inv(5), .2) - self.assertEqual(c.inv(0), "Err") - self.assertEqual(c.inv(-5), -.2) + self.assertEqual(c.invert(5), .2) + self.assertEqual(c.invert(0), "Err") + self.assertEqual(c.invert(-5), -.2) - def test_sine(self): - pass + def test_sin(self): + c = Calculator() + c.degrees = False + half_pi = .5 * math.pi + self.assertEqual(c.sin(half_pi),1) + self.assertEqual(c.sin("sdf"),"Err") + c.degrees = True + self.assertEqual(c.sin(90), 1) def test_cosine(self): - pass + c = Calculator() + c.degrees = False + half_pi = .5 * math.pi + self.assertAlmostEqual(c.cosine(half_pi),0) + self.assertEqual(c.cosine("sdf"),"Err") + c.degrees = True + self.assertAlmostEqual(c.cosine(90), 0) def test_tangent(self): - pass + c = Calculator() + c.degrees = False + quarter_pi = .25 * math.pi + self.assertAlmostEqual(c.tangent(quarter_pi),1) + self.assertEqual(c.tangent("sdf"),"Err") + c.degrees = True + self.assertAlmostEqual(c.tangent(45), 1) def test_invsine(self): - pass - - + c = Calculator() + c.degrees = False + half_pi = .5 * math.pi + self.assertEqual(c.inverse_sine(1),half_pi) + self.assertEqual(c.inverse_sine("sdfsdf"),"Err") + c.degrees = True + self.assertEqual(c.inverse_sine(1),90) + + def test_inverse_cosine(self): + c = Calculator() + c.degrees = False + half_pi = .5 * math.pi + self.assertEqual(c.inverse_cosine(0),half_pi) + self.assertEqual(c.inverse_cosine("sdfsdf"),"Err") + c.degrees = True + self.assertEqual(c.inverse_cosine(0),90) + + def test_inverse_tangent(self): + c = Calculator() + c.degrees = False + quarter_pi = .25 * math.pi + self.assertEqual(c.inverse_tangent(1),quarter_pi) + self.assertEqual(c.inverse_tangent("sdfsdf"),"Err") + c.degrees = True + self.assertEqual(c.inverse_tangent(1),45) if __name__ == '__main__': From afcaf2c011f99add35fb9072383e0afb8b4765aa Mon Sep 17 00:00:00 2001 From: Drake Dwornik Date: Mon, 1 Nov 2021 07:29:37 -0400 Subject: [PATCH 41/44] put main loop in __init__ --- main_app.py | 52 ++++++++++++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/main_app.py b/main_app.py index 8101aa0..9db09ea 100644 --- a/main_app.py +++ b/main_app.py @@ -324,34 +324,34 @@ def secondary_operation(): #loop does not operate correctly while welcome and main are defined as functions, must keep open - -print("Welcome to our Calculator!") -print("How can we help you?") -print("") - +def welcome(): + print("Welcome to our Calculator!") + print("How can we help you?") + print("") -condi = True -while condi: - calc.result = screen_options() - print(f"Result: {calc.result}") - choose_data_type() - print("") - cont = (input("Do you continue with this number? Y or N: ")).capitalize() - print("") - if cont == "Y": - condi2 = True - while condi2: - calc.result = secondary_operation() - print(f"Result: {calc.result}") - choose_data_type() - print("") - cont2 = (input("Do you continue with this number? Y or N: ")).capitalize() - print("") - if cont2 == "Y": - condi2 = True - else: - break +def main(): + condi = True + while condi: + calc.result = screen_options() + print(f"Result: {calc.result}") + choose_data_type() + print("") + cont = (input("Do you continue with this number? Y or N: ")).capitalize() + print("") + if cont == "Y": + condi2 = True + while condi2: + calc.result = secondary_operation() + print(f"Result: {calc.result}") + choose_data_type() + print("") + cont2 = (input("Do you continue with this number? Y or N: ")).capitalize() + print("") + if cont2 == "Y": + condi2 = True + else: + break From 8ea073ddd8c169489ed74e1a1160755fb0ead150 Mon Sep 17 00:00:00 2001 From: Drake Dwornik Date: Mon, 1 Nov 2021 08:35:57 -0400 Subject: [PATCH 42/44] added error removed second loop --- calculator.py | 10 ++++++- main_app.py | 76 +++++++++++++++++++++++++++------------------------ 2 files changed, 49 insertions(+), 37 deletions(-) diff --git a/calculator.py b/calculator.py index 516ca88..4738c88 100644 --- a/calculator.py +++ b/calculator.py @@ -70,6 +70,7 @@ def divide(self, x, y): except: result = "Err" self.err() + return result return result @@ -242,7 +243,7 @@ def multiply2(self, x): :param x: :return: """ - print( self.result * x) + # print( self.result * x) return self.result * x @@ -256,4 +257,11 @@ def divide2(self, x): print(self.result / x) return self.result / x + def clr(self,ce): + test = ce.upper() + if test == "CE": + print("ce") + self.error = False + result = 0 + diff --git a/main_app.py b/main_app.py index 9db09ea..9e9db74 100644 --- a/main_app.py +++ b/main_app.py @@ -30,49 +30,50 @@ def screen_options(): print("6: Square Root 13: Inverse Consine 20: Evaluate") print("7: Exponent 14: Inverse Tangent 21: Exit") print("") + print(f"Current number is: {calc.result}") Operation = int(input("Choose an operation: (Select the number) ")) memStore = None if Operation == 1: print("Add") - print("Enter the first number: ") + print(f"Enter number to add to {calc.result}: ") x = enter_num() - print("Enter the second number: ") - y = enter_num() - calc.result = calc.add(x ,y) + # print("Enter the second number: ") + # y = enter_num() + calc.result = calc.add(calc.result ,x) return calc.result elif Operation == 2: print("Subtract") - print("Enter the first number: ") + print(f"Enter number to subtract from {calc.result}: ") x = enter_num() - print("Enter the second number: ") - y = enter_num() - calc.result = calc.subtract(x, y) + # print("Enter the second number: ") + # y = enter_num() + calc.result = calc.subtract(calc.result, x) return calc.result elif Operation == 3: print("Multiply") - print("Enter the first number: ") + print(f"Enter number to multiply by {calc.result}: ") x = enter_num() - print("Enter the second number: ") - y = enter_num() - calc.result = calc.multiply(x, y) + # print("Enter the second number: ") + # y = enter_num() + calc.result = calc.multiply(calc.result, x) return calc.result elif Operation == 4: print("Divide") - print("Enter the first number: ") + print(f"Enter number to divide into {calc.result}: ") x = enter_num() - print("Enter the second number: ") - y = enter_num() - if y == 0: - print("ERROR") - return None - else: - calc.result = calc.divide(x, y) - return calc.result + # print("Enter the second number: ") + # y = enter_num() + # if y == 0: + # print("ERROR") + # return None + # else: + calc.result = calc.divide(calc.result, x) + return calc.result elif Operation == 5: print("Square") @@ -335,23 +336,26 @@ def main(): while condi: calc.result = screen_options() print(f"Result: {calc.result}") + while calc.error: + ce = input("an error occurered'CE' (Clear Error) to continue") + calc.clr(ce) choose_data_type() print("") - cont = (input("Do you continue with this number? Y or N: ")).capitalize() - print("") - if cont == "Y": - condi2 = True - while condi2: - calc.result = secondary_operation() - print(f"Result: {calc.result}") - choose_data_type() - print("") - cont2 = (input("Do you continue with this number? Y or N: ")).capitalize() - print("") - if cont2 == "Y": - condi2 = True - else: - break + # cont = (input("Do you continue with this number? Y or N: ")).capitalize() + # print("") + # if cont == "Y": + # condi2 = True + # while condi2: + # calc.result = secondary_operation() + # print(f"Result: {calc.result}") + # choose_data_type() + # print("") + # cont2 = (input("Do you continue with this number? Y or N: ")).capitalize() + # print("") + # if cont2 == "Y": + # condi2 = True + # else: + # break From 71b1202f6ceef85f78400dd44b2b38d9302fe2a5 Mon Sep 17 00:00:00 2001 From: Drake Dwornik Date: Mon, 1 Nov 2021 08:46:57 -0400 Subject: [PATCH 43/44] switching through to single loop --- calculator.py | 2 +- main_app.py | 23 +++++++++++------------ 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/calculator.py b/calculator.py index 4738c88..46fea1c 100644 --- a/calculator.py +++ b/calculator.py @@ -262,6 +262,6 @@ def clr(self,ce): if test == "CE": print("ce") self.error = False - result = 0 + self.result = 0 diff --git a/main_app.py b/main_app.py index 9e9db74..c19a15d 100644 --- a/main_app.py +++ b/main_app.py @@ -77,25 +77,24 @@ def screen_options(): elif Operation == 5: print("Square") - print("Enter the number: ") - base = enter_num() - calc.result = square(base) + # print("Enter the number: ") + calc.result = calc.square(calc.result) return calc.result - elif Operation == 6: + elif Operation == 7: print("Exponent") - print("Enter the base number: ") + print(f"Raise {calc.result} to the (enter number) power: ") x = enter_num() - print("Enter the exponent") - y = enter_num() - calc.result = calc.exp(x, y) + # print("Enter the exponent") + # y = enter_num() + calc.result = calc.exp(calc.result, x) return calc.result - elif Operation == 7: + elif Operation == 6: print("Square Root") - print("Enter the number: ") - x = enter_num() - calc.result = calc.square_root(x) + # print("Enter the number: ") + # x = enter_num() + calc.result = calc.square_root(calc.result) return calc.result elif Operation == 8: From 883c07b60bf68004716a44083c56d202db8b9858 Mon Sep 17 00:00:00 2001 From: Drake Dwornik Date: Mon, 1 Nov 2021 08:58:48 -0400 Subject: [PATCH 44/44] added more error handling --- calculator.py | 2 +- main_app.py | 90 +++++++++++++++++++++++++++------------------------ 2 files changed, 49 insertions(+), 43 deletions(-) diff --git a/calculator.py b/calculator.py index 46fea1c..ab0c323 100644 --- a/calculator.py +++ b/calculator.py @@ -23,6 +23,7 @@ def eval_function(self, x: str): result = eval(x) return result except: + self.err() return "Err" @@ -260,7 +261,6 @@ def divide2(self, x): def clr(self,ce): test = ce.upper() if test == "CE": - print("ce") self.error = False self.result = 0 diff --git a/main_app.py b/main_app.py index c19a15d..f4cab45 100644 --- a/main_app.py +++ b/main_app.py @@ -22,15 +22,20 @@ def enter_num(): ##Calculator Options def screen_options(): + if calc.degrees: + raddeg = "Degrees" + else: + raddeg = "Radians" + print("1: Add 8: Inverse 15: M+") print("2: Subtract 9: Sine 16: MC") print("3: Multiply 10: Cosine 17: MRC") - print("4: Divide 11: Tangent 18: Swap") + print("4: Divide 11: Tangent 18: Swap Trig") print("5: Square 12: Inverse Sine 19: Pi") print("6: Square Root 13: Inverse Consine 20: Evaluate") print("7: Exponent 14: Inverse Tangent 21: Exit") print("") - print(f"Current number is: {calc.result}") + print(f"Current number is: {calc.result} and trig functions are in {raddeg}") Operation = int(input("Choose an operation: (Select the number) ")) memStore = None @@ -99,9 +104,9 @@ def screen_options(): elif Operation == 8: print("Inverse") - print("Enter the number: ") - x = enter_num() - calc.result = calc.invert(x) + # print("Enter the number: ") + # x = enter_num() + calc.result = calc.invert(calc.result) return calc.result ##TRIG FUNCTIONS @@ -109,65 +114,64 @@ def screen_options(): elif Operation == 9: print("Sine") - if calc.degrees: - print("Enter a number in degrees to find Sine: ") - else: - print("Enter a number in radians to find Sine: ") - x = enter_num() - calc.result = calc.sin(x) + # if calc.degrees: + # print("Enter a number in degrees to find Sine: ") + # else: + # print("Enter a number in radians to find Sine: ") + calc.result = calc.sin(calc.result) return calc.result elif Operation == 10: print("Cosine") - if calc.degrees: - print("Enter an angle in degrees to find Cosine: ") - else: - print("Enter an angle in radians to find Cosine: ") - x = enter_num() - calc.result = calc.cosine(x) + # if calc.degrees: + # print("Enter an angle in degrees to find Cosine: ") + # else: + # print("Enter an angle in radians to find Cosine: ") + # x = enter_num() + calc.result = calc.cosine(calc.result) return calc.result elif Operation == 11: print("Tangent") - if calc.degrees: - print("Enter an angle in degrees to find Tangent: ") - else: - print("Enter an angle in radians to find Tangent: ") - x = enter_num() - calc.result = calc.tangent(x) + # if calc.degrees: + # print("Enter an angle in degrees to find Tangent: ") + # else: + # print("Enter an angle in radians to find Tangent: ") + # x = enter_num() + calc.result = calc.tangent(calc.result) return calc.result elif Operation == 12: print("Inverse Sine") - if calc.degrees: - print("Enter a number to find the arc sine in degrees: ") - else: - print("Enter a number to find the arc sine in radians: ") - x = enter_num() - result = calc.inverse_sine(x) + # if calc.degrees: + # print("Enter a number to find the arc sine in degrees: ") + # else: + # print("Enter a number to find the arc sine in radians: ") + # x = enter_num() + result = calc.inverse_sine(calc.result) return result elif Operation == 13: print("Inverse Cosine") - if calc.degrees: - print("Enter an angle in degrees to find Inverse Cosine: ") - else: - print("Enter an angle in radians to find Inverse Cosine: ") - x = enter_num() - calc.result = calc.inverse_cosine(x) + # if calc.degrees: + # print("Enter an angle in degrees to find Inverse Cosine: ") + # else: + # print("Enter an angle in radians to find Inverse Cosine: ") + # x = enter_num() + calc.result = calc.inverse_cosine(calc.result) return calc.result elif Operation == 14: print("Inverse Tangent") - if calc.degrees: - print("Enter an angle in degrees to find Inverse Tangent: ") - else: - print("Enter an angle in radians to find Inverse Tangent: ") - x = enter_num() - calc.result = calc.inverse_tangent(x) + # if calc.degrees: + # print("Enter an angle in degrees to find Inverse Tangent: ") + # else: + # print("Enter an angle in radians to find Inverse Tangent: ") + # x = enter_num() + calc.result = calc.inverse_tangent(calc.result) return calc.result ##MEMORY FUNCTIONS @@ -206,10 +210,12 @@ def screen_options(): elif Operation == 20: print("Evaluate") - x = str(input("Enter what you would like evaluated: ")) + x = input("Enter what you would like evaluated: ") calc.result = calc.eval_function(x) return calc.result + + elif Operation == 21: condi = False print("Thank you for pushing my buttons!")