fval = float(fval_str) which_num = 2 fval_str = "" sval_str = "" op = curr_key print(curr_key, end='', flush=True) #Clears the stored memory when "m" is cleared. if (curr_key == 'm' or curr_key == 'M'): calculator.clear_mem() print("Memory Cleared") print(">", end='', flush=True) #Inverts the current value's sign when "i" is pressed. if (curr_key == 'i' or curr_key == 'I'): result = calculator.invert(result) fval_str = str(result) print("Current value inverted. (" + str(result) + ")") print(">", end='', flush=True) #Saves current value in the calculator when "s" is pressed. if (curr_key == 's' or curr_key == 'S'): calculator.save_mem(result) print("Value saved!") print(">", end='', flush=True) #Resets all values in the calculator when "c" is pressed. if (curr_key == 'c' or curr_key == 'C'): fval = 0.0 sval = 0.0 fval_str = ""
def testInvert(self): self.assertEqual(calc.invert(5), -5) self.assertEqual(calc.invert(-90), 90) self.assertEqual(calc.invert(53450), -53450)
print (value) elif (oper == '-'): value = calculator.subtract (n1, n2) print (value) elif (oper == '*'): value = calculator.multiply (n1, n2) print (value) elif (oper =='/'): value = calculator.divide (n1, n2) # hey pull up the calcultaor function print (value) elif (oper.upper == "I"): # if user inputs lower case or uppercase I value = calculator.invert (n1) print (value) elif (oper == '^'): value = calculator.power (n1, n2 ) print (value) elif (oper=='r'): calculator.recall elif (op == 's'): calculator.cur_store n1= float(input("Enter first number ")) #user enters the first number n2= float(input("Enter second number ")) #user enters the second number oper= str(input("Please select operation +, - , * , or / ")) # user selects the operative
def tests_Invert(self): self.assertEqual(calculator.invert(4), -4) self.assertEqual(calculator.invert(-15), 15) self.assertEqual(calculator.invert(99), -99)
if op == '+': value = calculator.add(float(num_1), float(num_2)) print(num_1, "+", num_2, "=", value) elif op == '-': value = calculator.sub(float(num_1), float(num_2)) print(num_1, "-", num_2, "=", value) elif op == '*': value = calculator.multi(float(num_1), float(num_2)) print(num_1, "*", num_2, "=", value) elif op == '/': value = calculator.divide(float(num_1), float(num_2)) print(num_1, "/", num_2, "=", value) elif op == 'memory_store': calculator.memory_store(value) elif op == 'memory_return': value = calculator.memory_return() print = (value) elif op == 'memory_clear': calculator.memory_clear elif op == 'invert': value = calculator.invert(num_1) print(value) elif op == 'power': value = calculator.power(float(num_1), float(num_2)) print(value)
#check for operator if (pressedKey == "+" or pressedKey == "-" or pressedKey == "*" or pressedKey == "/" or pressedKey == "^"): if (number == 1): num1 = float(num1Str) number = 2 num1Str = "" num2Str = "" oper = pressedKey print(pressedKey, end='', flush=True) #check for and execute calculator functions if (pressedKey == "I" or pressedKey == "i"): result = calc.invert(result) num1Str = str(result) print(result) print(">>", end='', flush=True) if (pressedKey == "C" or pressedKey == "c"): num1 = 0.0 num2 = 0.0 num1Str = "" num2Str = "" number = 1 result = 0.0 expressionIsDone = False print("Calculator cleared") print(">>", end='', flush=True)
elif oper == "^": answer = calculator.pow(num1,num2) num1 = answer return (answer) elif oper == "i" or "I": answer = calculator.invert(num1) num1 = answer return (answer) elif oper == "c" or "C": answer = calculator.memClear(num1) num1 = answer return ("Memory cleared.")
def test_invert(self): self.assertEqual(invert(5), -5)
def testInvert(self): self.assertEqual(calculator.invert(0), 0) self.assertEqual(calculator.invert(-4), 4) self.assertEqual(calculator.invert(-11), 11)
print("5.Power") print("r.Recall") print("i.Invert") print("c.Clear") print("x.Exit") # while loop for calculation while (True): choice = input("Enter choice(1/2/3/4/5/r/i/c/x):") if choice == 'r': print(calculator.getMemoryValue()) continue elif choice == 'i': print(calculator.invert()) continue elif choice == 'c': print(calculator.clearMemory()) continue elif choice == 'x': break if choice != '1' and choice != '2' and choice != '3' and choice != '4' and choice != '5' and choice != 'r' and choice != 'i' and choice != 'c': print("Invalid choice") continue try: if operator == '': strleftValue = "" while (not strleftValue.isdigit()): strleftValue = input("Enter first number: ")