示例#1
0
 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)
示例#2
0
    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)
示例#3
0
 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)
示例#4
0
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
示例#5
0
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
示例#6
0
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
示例#7
0
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
示例#8
0
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)
示例#9
0
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)
示例#10
0
def multiply(a, b):
    c = Calculator()

    result = c.mul(int(a), int(b))
    return str(result)
示例#11
0
def divide(a, b):
    c = Calculator()

    result = c.div(int(a), int(b))
    return str(result)
示例#12
0
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))