Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1. 다음 special method들의 기능을 확인하세요
- object.__call__(self[, args...]) - 생성된 인스턴스를 함수 처럼 호출 가능하게 해준다.
- 클래스 내에서 이 메서드가 정의되면,
- 인스턴스 x 는 x(arg1, arg2, ...) 와 같이 함수 형태로 호출이 가능하다.
- x(arg1, arg2, ...) 는 x.__call__(arg1, arg2, ...) 의 줄인 표현이다.
- class Factorial:
- def __init__(self):
- self.cache = {}
- def __call__(self, n):
- if n not in self.cache:
- if n == 0:
- self.cache[n] = 1
- else:
- self.cache[n] = n * self.__call__(n - 1)
- return self.cache[n]
- fact = Factorial()
- for i in range(10):
- print ('%d! = %d' % (i, fact(i)))
- object.__len__(self) - 생성된 인스턴스를 내장함수 len() 에 사용할수 있도록 해준다.
- 이 메서드를 정의하지 않고 len(x) 처럼 사용하면 TypeError: object of type 'Factorial' has no len() 와 같은 에러를 낸다.
- class Factorial:
- def __init__(self):
- self.cache = {}
- def __call__(self, n):
- if n not in self.cache:
- if n == 0:
- self.cache[n] = 1
- else:
- self.cache[n] = n * self.__call__(n - 1)
- return self.cache[n]
- def __len__(self):
- return len(self.cache)
- fact = Factorial()
- for i in range(10):
- print ('%d! = %d' % (i, fact(i)))
- print(len(fact))
- object.__contains__(self, item) - 멤버십 검사 연산자를 구현하기 위해 호출된다. (in 또는 not in)
- item 이 self 에 있으면 참을, 그렇지 않으면 거짓을 돌려줘야 한다.
- 매핑 객체의 경우, 키-값 쌍이 아니라 매핑의 키가 고려되어야 한다.
- class Factorial:
- def __init__(self):
- self.cache = {}
- def __call__(self, n):
- if n not in self.cache:
- if n == 0:
- self.cache[n] = 1
- else:
- self.cache[n] = n * self.__call__(n - 1)
- return self.cache[n]
- def __len__(self):
- return len(self.cache)
- def __contains__(self, item):
- if item in self.cache.keys():
- return True
- else:
- return False
- fact = Factorial()
- for i in range(10):
- print ('%d! = %d' % (i, fact(i)))
- print(9 in fact)
- print(11 in fact)
- object.__getitem__(self, key) - self[key] 의 값을 구하기 위해 호출된다.
- 시퀸스형이나 매핑형 객체들 처럼 객체[키] 형태로 사용한다.
- class Factorial:
- def __init__(self):
- self.cache = {}
- def __call__(self, n):
- if n not in self.cache:
- if n == 0:
- self.cache[n] = 1
- else:
- self.cache[n] = n * self.__call__(n - 1)
- return self.cache[n]
- def __len__(self):
- return len(self.cache)
- def __contains__(self, item):
- if item in self.cache.keys():
- return True
- else:
- return False
- def __getitem__(self, key):
- return self.cache[key]
- fact = Factorial()
- for i in range(10):
- print ('%d! = %d' % (i, fact(i)))
- print(fact[3])
- object.__setitem__(self, key, value) - self[key] 로의 대입을 구현하기 위해 호출된다.
- class Factorial:
- def __init__(self):
- self.cache = {}
- def __call__(self, n):
- if n not in self.cache:
- if n == 0:
- self.cache[n] = 1
- else:
- self.cache[n] = n * self.__call__(n - 1)
- return self.cache[n]
- def __len__(self):
- return len(self.cache)
- def __contains__(self, item):
- if item in self.cache.keys():
- return True
- else:
- return False
- def __getitem__(self, key):
- return self.cache[key]
- def __setitem__(self, key, value):
- self.cache[key] = value
- fact = Factorial()
- for i in range(10):
- print ('%d! = %d' % (i, fact(i)))
- fact[11] = 256
- print(fact[11])
- object.__delitem__(self, key) - self[key] 의 삭제를 구현하기 위해 호출된다.
- class Factorial:
- def __init__(self):
- self.cache = {}
- def __call__(self, n):
- if n not in self.cache:
- if n == 0:
- self.cache[n] = 1
- else:
- self.cache[n] = n * self.__call__(n - 1)
- return self.cache[n]
- def __len__(self):
- return len(self.cache)
- def __contains__(self, item):
- if item in self.cache.keys():
- return True
- else:
- return False
- def __getitem__(self, key):
- return self.cache[key]
- def __setitem__(self, key, value):
- self.cache[key] = value
- def __delitem__(self, key):
- del self.cache[key]
- def print_cache(self):
- print(self.cache)
- fact = Factorial()
- for i in range(10):
- fact(i)
- fact.print_cache()
- del fact[3]
- fact.print_cache()
- object.__add__(self, other) - 같은 클래스로 생성된 인스턴스 끼리 덧셈이 가능하도록 한다.
- class Factorial:
- def __init__(self):
- self.cache = {}
- def __call__(self, n):
- if n not in self.cache:
- if n == 0:
- self.cache[n] = 1
- else:
- self.cache[n] = n * self.__call__(n - 1)
- return self.cache[n]
- def __len__(self):
- return len(self.cache)
- def __contains__(self, item):
- if item in self.cache.keys():
- return True
- else:
- return False
- def __getitem__(self, key):
- return self.cache[key]
- def __setitem__(self, key, value):
- self.cache[key] = value
- def __delitem__(self, key):
- del self.cache[key]
- def __add__(self, other):
- return {**self.cache, **other.cache}
- def print_cache(self):
- print(self.cache)
- fact = Factorial()
- for i in range(10):
- fact(i)
- fact.print_cache()
- fact2 = Factorial()
- for i in range(5, 15):
- fact2(i)
- del(fact2[0])
- del(fact2[1])
- del(fact2[2])
- del(fact2[3])
- del(fact2[4])
- del(fact2[5])
- del(fact2[6])
- fact2.print_cache()
- print(fact + fact2)
- object.__sub__(self, other) - 같은 클래스로 생성된 인스턴스 끼리 뺄셈이 가능하도록 한다.
- class Factorial:
- def __init__(self):
- self.cache = {}
- def __call__(self, n):
- if n not in self.cache:
- if n == 0:
- self.cache[n] = 1
- else:
- self.cache[n] = n * self.__call__(n - 1)
- return self.cache[n]
- def __len__(self):
- return len(self.cache)
- def __contains__(self, item):
- if item in self.cache.keys():
- return True
- else:
- return False
- def __getitem__(self, key):
- return self.cache[key]
- def __setitem__(self, key, value):
- self.cache[key] = value
- def __delitem__(self, key):
- del self.cache[key]
- def __add__(self, other):
- return {**self.cache, **other.cache}
- def __sub__(self, other):
- x = self.cache.copy()
- other_keys = other.cache.keys()
- for key in self.cache.keys():
- if key in other_keys:
- del x[key]
- return x
- def print_cache(self):
- print(self.cache)
- fact = Factorial()
- for i in range(10):
- fact(i)
- fact.print_cache()
- fact2 = Factorial()
- for i in range(5, 15):
- fact2(i)
- del(fact2[0])
- del(fact2[1])
- del(fact2[2])
- del(fact2[3])
- del(fact2[4])
- del(fact2[5])
- del(fact2[6])
- fact2.print_cache()
- print(fact - fact2)
- object.__mul__(self, other) - 같은 클래스로 생성된 인스턴스 끼리 곱셈이 가능하도록 한다.
- class Factorial:
- def __init__(self):
- self.cache = {}
- def __call__(self, n):
- if n not in self.cache:
- if n == 0:
- self.cache[n] = 1
- else:
- self.cache[n] = n * self.__call__(n - 1)
- return self.cache[n]
- def __len__(self):
- return len(self.cache)
- def __contains__(self, item):
- if item in self.cache.keys():
- return True
- else:
- return False
- def __getitem__(self, key):
- return self.cache[key]
- def __setitem__(self, key, value):
- self.cache[key] = value
- def __delitem__(self, key):
- del self.cache[key]
- def __add__(self, other):
- return {**self.cache, **other.cache}
- def __sub__(self, other):
- x = self.cache.copy()
- other_keys = other.cache.keys()
- for key in self.cache.keys():
- if key in other_keys:
- del x[key]
- return x
- def __mul__(self, other):
- x = {}
- all = self.__add__(other)
- self_keys = self.cache.keys()
- other_keys = other.cache.keys()
- for key in all.keys():
- if key in self_keys and key in other_keys:
- x[key] = self.cache[key] * other.cache[key]
- else:
- x[key] = 0
- return x
- def print_cache(self):
- print(self.cache)
- fact = Factorial()
- for i in range(10):
- fact(i)
- fact.print_cache()
- fact2 = Factorial()
- for i in range(5, 15):
- fact2(i)
- del(fact2[0])
- del(fact2[1])
- del(fact2[2])
- del(fact2[3])
- del(fact2[4])
- del(fact2[5])
- del(fact2[6])
- fact2.print_cache()
- print(fact * fact2)
- object.__truediv__(self, other) - 같은 클래스로 생성된 인스턴스 끼리 나눗셈이 가능하도록 한다.
- class Factorial:
- def __init__(self):
- self.cache = {}
- def __call__(self, n):
- if n not in self.cache:
- if n == 0:
- self.cache[n] = 1
- else:
- self.cache[n] = n * self.__call__(n - 1)
- return self.cache[n]
- def __len__(self):
- return len(self.cache)
- def __contains__(self, item):
- if item in self.cache.keys():
- return True
- else:
- return False
- def __getitem__(self, key):
- return self.cache[key]
- def __setitem__(self, key, value):
- self.cache[key] = value
- def __delitem__(self, key):
- del self.cache[key]
- def __add__(self, other):
- return {**self.cache, **other.cache}
- def __sub__(self, other):
- x = self.cache.copy()
- other_keys = other.cache.keys()
- for key in self.cache.keys():
- if key in other_keys:
- del x[key]
- return x
- def __mul__(self, other):
- x = {}
- all = self.__add__(other)
- self_keys = self.cache.keys()
- other_keys = other.cache.keys()
- for key in all.keys():
- if key in self_keys and key in other_keys:
- x[key] = self.cache[key] * other.cache[key]
- else:
- x[key] = 0
- return x
- def __truediv__(self, other):
- x = {}
- all = self.__add__(other)
- self_keys = self.cache.keys()
- other_keys = other.cache.keys()
- for key in all.keys():
- if key in self_keys and key in other_keys:
- if other.cache[key]:
- x[key] = self.cache[key] / other.cache[key]
- else:
- x[key] = None
- else:
- x[key] = None
- return x
- def print_cache(self):
- print(self.cache)
- fact = Factorial()
- for i in range(10):
- fact(i)
- fact.print_cache()
- fact2 = Factorial()
- for i in range(5, 15):
- fact2(i)
- del(fact2[0])
- del(fact2[1])
- del(fact2[2])
- del(fact2[3])
- del(fact2[4])
- del(fact2[5])
- del(fact2[6])
- fact2.print_cache()
- print(fact / fact2)
- object.__lt__(self, other)
- object.__le__(self, other)
- object.__eq__(self, other)
- object.__ne__(self, other)
- object.__gt__(self, other)
- object.__ge__(self, other)
- 이것들은 소위 "풍부한 비교(rich comparison)" 메서드다.
- 연산자 기호와 메서드 이름 간의 관계는 다음과 같다:
- x<y 는 x.__lt__(y) 를 호출한다,
- x<=y 는 x.__le__(y) 를 호출한다,
- x==y 는 x.__eq__(y) 를 호출한다,
- x!=y 는 x.__ne__(y) 를 호출한다,
- x>y 는 x.__gt__(y) 를 호출한다,
- x>=y 는 x.__ge__(y) 를 호출한다.
- class Factorial:
- def __init__(self):
- self.cache = {}
- def __call__(self, n):
- if n not in self.cache:
- if n == 0:
- self.cache[n] = 1
- else:
- self.cache[n] = n * self.__call__(n - 1)
- return self.cache[n]
- def __len__(self):
- return len(self.cache)
- def __contains__(self, item):
- if item in self.cache.keys():
- return True
- else:
- return False
- def __getitem__(self, key):
- return self.cache[key]
- def __setitem__(self, key, value):
- self.cache[key] = value
- def __delitem__(self, key):
- del self.cache[key]
- def __add__(self, other):
- return {**self.cache, **other.cache}
- def __sub__(self, other):
- x = self.cache.copy()
- other_keys = other.cache.keys()
- for key in self.cache.keys():
- if key in other_keys:
- del x[key]
- return x
- def __mul__(self, other):
- x = {}
- all = self.__add__(other)
- self_keys = self.cache.keys()
- other_keys = other.cache.keys()
- for key in all.keys():
- if key in self_keys and key in other_keys:
- x[key] = self.cache[key] * other.cache[key]
- else:
- x[key] = 0
- return x
- def __truediv__(self, other):
- x = {}
- all = self.__add__(other)
- self_keys = self.cache.keys()
- other_keys = other.cache.keys()
- for key in all.keys():
- if key in self_keys and key in other_keys:
- if other.cache[key]:
- x[key] = self.cache[key] / other.cache[key]
- else:
- x[key] = None
- else:
- x[key] = None
- return x
- def __lt__(self, other): # self < other
- return sum(self.cache.values()) < sum(other.cache.values())
- def __le__(self, other): # self <= other
- return sum(self.cache.values()) <= sum(other.cache.values())
- def __eq__(self, other): # self == other
- return sum(self.cache.values()) == sum(other.cache.values())
- def __ne__(self, other): # self != other
- return sum(self.cache.values()) != sum(other.cache.values())
- def __gt__(self, other): # self > other
- return sum(self.cache.values()) > sum(other.cache.values())
- def __ge__(self, other): # self >= other
- return sum(self.cache.values()) >= sum(other.cache.values())
- def print_cache(self):
- print(self.cache)
- fact = Factorial()
- for i in range(10):
- fact(i)
- fact.print_cache()
- fact2 = Factorial()
- for i in range(5, 15):
- fact2(i)
- del(fact2[0])
- del(fact2[1])
- del(fact2[2])
- del(fact2[3])
- del(fact2[4])
- del(fact2[5])
- del(fact2[6])
- fact2.print_cache()
- print(fact < fact2)
- print(fact <= fact2)
- print(fact == fact2)
- print(fact != fact2)
- print(fact > fact2)
- print(fact >= fact2)
- 2. Account Class 업그레이드
- 수업에서 활용한 account class에 다음 기능을 추가하세요
- 1. 계좌 생성시에 password 지정 및 은행이름 입력.
- 2. 송금시에 password 입력 및 일치하는지 확인
- 3. 송금시에 같은 은행이 아닌 경우에는 수수로 -500 원 별도 부여
- 4. 소유자가 같은 계좌는 + 연산자로 보유금액 합산가능
- 5. 소유자가 같은지 == 연산자 혹은 != 연산자로 확인가능
- class Wallet:
- # object.__init__(self[, ...])
- # (__new__() 에 의해) 인스턴스가 만들어진 후에, 하지만 호출자에게 돌려주기 전에 호출된다.
- # 인자들은 클래스 생성자 표현으로 전달된 것들이다. 만약 베이스 클래스가 __init__() 메서드를 갖고 있다면,
- # 서브 클래스의 __init__() 메서드는, 있다면, 인스턴스에서 베이스 클래스가 차지하는 부분이 올바르게 초기화됨을 확실히 하기 위해 명시적으로 호출해주어야 한다;
- # 예를 들어: super().__init__([args...]).
- def __init__(self, name):
- self.money = 0
- self.owner = name
- print(f"{name}님 환영합니다.[__init__]")
- # object.__str__(self)
- # str(object) 와 내장 함수 format(), print() 에 의해 호출되어 객체의 "비형식적인(informal)" 또는 보기 좋게 인쇄 가능한 문자열 표현을 계산한다.
- # 반환 값은 반드시 문자열 객체여야 한다.
- def __str__(self):
- return f'{self.owner}님의 지갑입니다.[__str__]'
- # object.__repr__(self)
- # repr() 내장 함수에 의해 호출되어 객체의 "형식적인(official)" 문자열 표현을 계산한다.
- # 만약 가능하다면, 이것은 같은 (적절한 환경이 주어질 때) 값을 갖는 객체를 새로 만들 수 있는 올바른 파이썬 표현식처럼 보여야 한다.
- # 가능하지 않다면, <...쓸모있는 설명...> 형태의 문자열을 돌려줘야 한다. 반환 값은 반드시 문자열이어야 한다.
- # 만약 클래스가 __str__() 없이 __repr__() 만 정의한다면, __repr__() 은 그 클래스 인스턴스의 "비형식적인(informal)" 문자열 표현이 요구될 때 사용될 수 있다.
- def __repr__(self):
- return f'{self.owner}님의 지갑입니다.[__repr__]'
- def print_owner_name(self):
- print("owner name is", self.owner)
- def print_now_money(self):
- print(f"현재 잔액은 {self.money}원 입니다.")
- def spend(self, m):
- if self.money < m:
- print("돈이 부족합니다.")
- self.print_now_money()
- else:
- self.money -= m
- print(f"{m}원을 지출했습니다.")
- self.print_now_money()
- def income(self, m):
- self.money += m
- self.print_now_money()
- class Account(Wallet):
- def __init__(self, name, account_number, password, bankname):
- super().__init__(name)
- self.account_number = account_number
- self.password = password
- self.bankname = bankname
- print(f"{name}님 계좌정보입니다. 은행: {bankname}, 계좌번호: {account_number}, 비밀번호: {password} [__init__]")
- def __add__(self, another):
- if self.owner == another.owner:
- return self.money + another.money
- else:
- return "각 계좌의 소유자가 달라서 잔액을 합산할수 없습니다."
- def send_money(self, money, password, to):
- if self.money >= money and self.password == password:
- if to.bankname == self.bankname:
- to.money += money
- self.money -= money
- print(f"{money}원을 {to.owner}에게 보냈습니다.")
- self.print_now_money()
- else:
- if self.money >= money + 500:
- to.money += money
- self.money -= money + 500
- print(f"{money}원을 {to.bankname} {to.owner}에게 보냈습니다. 수수료는 500원 입니다.")
- self.print_now_money()
- else:
- print("돈이 부족합니다.")
- elif self.password == password:
- print("돈이 부족합니다.")
- else:
- print("비밀번호가 잘못 되었습니다.")
- # my_wallet = Wallet('유창화')
- # print(str(my_wallet))
- # print(repr(my_wallet))
- # my_wallet.income(100000)
- # my_wallet.spend(5000000)
- # my_wallet.spend(50000)
- # my_account = Account('유창화', '123-12345', '12345', '국민')
- # print(str(my_account))
- # print(repr(my_account))
- my_account = Account('유창화', '123-12345', '12345', '국민')
- my_account2 = Account('유창래', '12345-123', '54321', '신한')
- my_account.income(1000000)
- my_account2.income(500000)
- sum_money = my_account + my_account2
- if str(sum_money).isnumeric():
- print(f"두 통장의 잔고 합계는 {my_account + my_account2}원 입니다.")
- else:
- print(sum_money)
- my_account.send_money(500000000, '12345', my_account2)
- my_account.send_money(500000, '123456', my_account2)
- my_account.send_money(500000, '12345', my_account2)
- 3. Bank Class 추가하기
- 1. 은행 대표번호와, 계좌 번호 생성 패턴을 입력하여 인스턴스 생성
- 예) shinhan = Bank(’02-1234-1234’, ‘xxx-xxxx-xxxx’)
- 2. 계좌 번호 생성하는 메소드를 만들어서 입력받은 패턴대로
- 랜덤한 숫자를 더하여 계좌번호 리턴
- 3. 업그레이드된 Account Class에서 인스턴스 생성시
- bank인스턴스도 같이 입력,
- bank instance의 메소드를 사용하여계좌 번호 자동생성되게 조정
- 4. 에러 발생시 은행 대표번호가 출력되어 문의 가능하도록 예외처리
- import re
- from random import randrange
- class Wallet:
- # object.__init__(self[, ...])
- # (__new__() 에 의해) 인스턴스가 만들어진 후에, 하지만 호출자에게 돌려주기 전에 호출된다.
- # 인자들은 클래스 생성자 표현으로 전달된 것들이다. 만약 베이스 클래스가 __init__() 메서드를 갖고 있다면,
- # 서브 클래스의 __init__() 메서드는, 있다면, 인스턴스에서 베이스 클래스가 차지하는 부분이 올바르게 초기화됨을 확실히 하기 위해 명시적으로 호출해주어야 한다;
- # 예를 들어: super().__init__([args...]).
- def __init__(self, name):
- self.money = 0
- self.owner = name
- print(f"{name}님 환영합니다.[__init__]")
- # object.__str__(self)
- # str(object) 와 내장 함수 format(), print() 에 의해 호출되어 객체의 "비형식적인(informal)" 또는 보기 좋게 인쇄 가능한 문자열 표현을 계산한다.
- # 반환 값은 반드시 문자열 객체여야 한다.
- def __str__(self):
- return f'{self.owner}님의 지갑입니다.[__str__]'
- # object.__repr__(self)
- # repr() 내장 함수에 의해 호출되어 객체의 "형식적인(official)" 문자열 표현을 계산한다.
- # 만약 가능하다면, 이것은 같은 (적절한 환경이 주어질 때) 값을 갖는 객체를 새로 만들 수 있는 올바른 파이썬 표현식처럼 보여야 한다.
- # 가능하지 않다면, <...쓸모있는 설명...> 형태의 문자열을 돌려줘야 한다. 반환 값은 반드시 문자열이어야 한다.
- # 만약 클래스가 __str__() 없이 __repr__() 만 정의한다면, __repr__() 은 그 클래스 인스턴스의 "비형식적인(informal)" 문자열 표현이 요구될 때 사용될 수 있다.
- def __repr__(self):
- return f'{self.owner}님의 지갑입니다.[__repr__]'
- def print_owner_name(self):
- print("owner name is", self.owner)
- def print_now_money(self):
- print(f"현재 잔액은 {self.money}원 입니다.")
- def spend(self, m):
- if self.money < m:
- print("돈이 부족합니다.")
- self.print_now_money()
- else:
- self.money -= m
- print(f"{m}원을 지출했습니다.")
- self.print_now_money()
- def income(self, m):
- self.money += m
- self.print_now_money()
- def get_rand_number_string(len):
- x = []
- for _ in range(len):
- x.append(str(randrange(10)))
- return ''.join(x)
- class Bank:
- # 정적 클래스 속성(변수), 모든 인스턴스가 공유, 클래스명이나 cls로 접근
- bank_instances = {} # 은행명은 중복이 없다고 보고 딕셔너리의 키값으로 사용
- # 인스턴스 가 생성하는 시점, 무분별한 인스턴스 생성을 막을수 있다.
- def __new__(cls, name, phone, account_number_pattern):
- if cls.bank_instances.get(name):
- return cls.bank_instances[name]
- else:
- bank = super().__new__(cls)
- cls.bank_instances[name] = bank
- return bank
- # 인스턴스 생성 직후 초기화
- def __init__(self, name, phone, account_number_pattern):
- self.name = re.sub('\s', '', name)
- self.phone = re.sub('[^0-9\\-]', '', phone)
- self.account_number_pattern = re.sub('[^x\\-]', '', account_number_pattern)
- print(f"{self.name} 정보입니다. 대표번호: {self.phone}, 계좌번호 패턴 : {self.account_number_pattern} [__init__]")
- def create_account_number(self):
- pattern = self.account_number_pattern.split('-')
- x = []
- for p in pattern:
- x.append(get_rand_number_string(len(p)))
- return '-'.join(x)
- def print_default_msg(self, msg=''):
- if msg:
- print(msg)
- print(f"자세한 문의사항은 {self.name} 대표번호 {self.phone} 으로 연락주십시오.")
- class Account(Wallet):
- def __init__(self, name, password, bank):
- super().__init__(name)
- self.password = password
- self.bank = bank
- self.account_number = bank.create_account_number()
- print(f"{self.owner}님 계좌정보입니다. 은행: {self.bank.name}, 계좌번호: {self.account_number}, 비밀번호: {self.password} [__init__]")
- def __add__(self, another):
- if self.owner == another.owner:
- return self.money + another.money
- else:
- self.bank.print_default_msg("각 계좌의 소유자가 달라서 잔액을 합산할수 없습니다.")
- return False
- def send_money(self, money, password, to):
- if self.money >= money and self.password == password:
- if to.bank is self.bank: # 동일한 인스턴스인지 비교
- to.money += money
- self.money -= money
- print(f"{money}원을 {to.owner}에게 보냈습니다.")
- self.print_now_money()
- else:
- if self.money >= money + 500:
- to.money += money
- self.money -= money + 500
- print(f"{money}원을 {to.bank.name} {to.owner}에게 보냈습니다. 수수료는 500원 입니다.")
- self.print_now_money()
- else:
- print("돈이 부족합니다.")
- self.bank.print_default_msg()
- elif self.password == password:
- print("돈이 부족합니다.")
- self.bank.print_default_msg()
- else:
- print("비밀번호가 잘못 되었습니다.")
- self.bank.print_default_msg()
- shinhan = Bank('신한은행', '02-1688-1788', 'xxx-xxxxx-xxxxxx')
- kookmin = Bank('국민은행', '02-15688-1688', 'xxxx-xxxxx-xxxxx')
- my_account = Account('유창화', '12345', shinhan)
- my_account2 = Account('유창래', '54321', kookmin)
- my_account.income(1000000)
- my_account2.income(500000)
- sum_money = my_account + my_account2
- if str(sum_money).isnumeric():
- print(f"두 통장의 잔고 합계는 {sum_money}원 입니다.")
- my_account.send_money(500000000, '12345', my_account2)
- my_account.send_money(500000, '123456', my_account2)
- my_account.send_money(500000, '12345', my_account2)
- print(shinhan.bank_instances)
- print(kookmin.bank_instances)
Add Comment
Please, Sign In to add comment