def test_twoMinusFourteenEqualsNegativeTwelve(self): calc = Calculator() calc.add_digit(2) calc.set_operation(operators["-"]) calc.add_digit(1) calc.add_digit(4) self.assertEqual(calc.get_result(), -12)
def __init__(self, parent): self.calculator = Calculator() window = PanedWindow(orient=VERTICAL) window.pack(fill=BOTH, expand=10) self.display = Label(window, text="0", justify=RIGHT) window.add(display) bottom = PanedWindow(orient=VERTICAL) zero = Button(bottom, text="0", command=add_digit(0)) one = Button(bottom, text="1", command=add_digit(0)) two = Button(bottom, text="2", command=add_digit(0)) three = Button(bottom, text="3", command=add_digit(0)) four = Button(bottom, text="4", command=add_digit(0)) five = Button(bottom, text="5", command=add_digit(0)) six = Button(bottom, text="6", command=add_digit(0)) seven = Button(bottom, text="7", command=add_digit(0)) eight = Button(bottom, text="8", command=add_digit(0)) nine = Button(bottom, text="9", command=add_digit(0)) bottom.pack(fill=BOTH, expand=1) bottom.add(zero) bottom.add(one) bottom.add(two) bottom.add(three) bottom.add(four) bottom.add(five) bottom.add(six) bottom.add(seven) bottom.add(eight) bottom.add(nine) window.add(bottom)
def test_twoPlusFourteenEqualsSixteen(self): calc = Calculator() calc.add_digit(2) calc.set_operation(operators["+"]) calc.add_digit(1) calc.add_digit(4) self.assertEqual(calc.get_result(), 16)
def multiply(a, b): c = Calculator() try: result = c.mul(int(a), int(b)) return str(result) except Exception, e: return str(e.args[0]), 403
def divide(a, b): c = Calculator() try: result = c.div(int(a), int(b)) return str(result) except Exception, e: return str(e.args[0]), 403
def multiply(a, b): c = Calculator() try: result = c.mul(int(a), int(b)) return str(result) except Exception as e: return e.message, 403
def divide(a, b): c = Calculator() try: result = c.div(int(a), int(b)) return str(result) except Exception as e: return e.message, 403
def multiply(a, b): c = Calculator() try: result = c.mul(int(a), int(b)) except ValueTooLowException: return 'Value too low', 403 except ValueTooHighException: return 'Value too high', 403 return str(result)
def divide(a, b): c = Calculator() try: result = c.div(int(a), int(b)) except ZeroDivisionError: return 'Division by 0', 403 except ValueTooLowException: return 'Value too low', 403 except ValueTooHighException: return 'Value too high', 403 return str(result)
def multiply(a, b): c = Calculator() result = c.mul(int(a), int(b)) return str(result)
def divide(a, b): c = Calculator() result = c.div(int(a), int(b)) return str(result)
from logic import Calculator operacao = input("Qual operação você deseja fazer: ") num1 = float(input("Indique um primeiro operador: ")) num2 = float(input("Indique o segundo operador: ")) # operacao = "**" # num1 = 10 # num2 = 5 print(Calculator().do_calc(operacao, num1, num2))