05 Python class - (2) class 예제

처어리·2024년 1월 25일

python

목록 보기
35/36
post-thumbnail

02. class 예제

하나의 은행 계좌를 관리하는 클래스를 구현하세요

  • class 명 : Account
  • 입금, 출금, 잔액확인이 가능합니다.
class Account:
    def __init__(self, number, balance=0):
        self.__number = number
        self.__balance = balance
    
    def getBalance(self):
        return self.__balance
    
    def deposit(self, money):
        self.__balance += money
        
    def withdraw(self, money):
        self.__balance -= money
    
    def showBalance(self):
        print(f"잔    액 : {self.__balance}")
    
    def info(self):
        print("--- 계 좌   정 보 ---")
        print(f"계좌번호 : {self.__number}")
        print(f"잔    액 : {self.__balance}")
        
        
memberA = Account("000123-10-123")
memberA.info()
print()
print("- 입 금 -")
memberA.deposit(20000)
memberA.showBalance()
print()
print("- 출 금 -")
memberA.withdraw(7000)
memberA.showBalance()
print()
memberA.info()

0개의 댓글