Ejemplo n.º 1
0
def calculate(operations_line):
    calcoo = CalculadoraHija()
    method, numbers = convert_line(operations_line)
    # Check if the method exists in the class
    if method not in dir(CalculadoraHija):
        raise SystemExit('Error: Operation unsupported')
    calcoo.ans = numbers[0]  # Temporarily assigns the first number to result
    for number in numbers[1:]:  # Skip 1st number assigned to ans
        getattr(calcoo, method)(calcoo.ans, number)
    calcoo.show()