import Calculator;
cal1 = Calculator.Calculator();
print(cal1.Add("gg", 2)); |
class Calculator: def __init__(self): self.result = 0;
def Add(self, number1, number2): result = 0; try: #Error Create #raise();
if(type(number1) != int or type(number2) != int): raise(); else: result = number1 + number2;
except Exception as e: return MyException();
return result;
def Sub(self, number1, number2): return number1 - number2;
class MyException(Exception): def __str__(self): return "숫자를 입력해주세요."; |
'Python' 카테고리의 다른 글
python chr (0) | 2019.09.06 |
---|---|
python all (0) | 2019.09.06 |
python exception (0) | 2019.09.06 |
python class2 (0) | 2019.09.06 |
python class (0) | 2019.09.04 |