コード例 #1
0
ファイル: calcoo.py プロジェクト: r-salas/ptavi-p2
def main():
    num1, operation, num2 = take_args()
    calcoo = Calculadora()
    # It checks if method exists in the class
    if operation not in dir(calcoo):
        raise SystemExit('Error: Operation unsupported')
    getattr(calcoo, operation)(num1, num2)  # Same as calcoo.operation(...)
    calcoo.show()
コード例 #2
0
ファイル: calcoohija.py プロジェクト: muris2016/ptavi-p2
#!/usr/bin/python3
# -*- coding:utf-8 -*-

import sys
import calc
import calcoo


class CalculadoraHija(calcoo.Calculadora):
    def __init__(self):
        super().__init__()
        self.operations["multiplica"] = self.multiply
        self.operations["divide"] = self.division

    def multiply(self, a, b):
        return a * b

    def division(self, a, b):
        try:
            return a / b
        except ZeroDivisionError:
            sys.exit("Division by zero is not allowed")


if __name__ == "__main__":
    op1, operation, op2 = calc.take_args()
    calc = CalculadoraHija()
    print(calcoo.do_operation(calc, operation, op1, op2))