파이썬 배운지 한달차
여러가지 도전적인 상황이 많이 발생했었습니다.
한달밖에 파이썬을 안 배웟는데 벌써부터 이런걸 한다구요?
한달밖에 안되서 이거 밖에 못하는거라고 말해주지 않겟어요... ㅠ
class Customer:
def __init__(self, account_name, account_number, opening_balance):
self.account_number = account_number
self.account_name = account_name
self.balance = opening_balance
#내가 사용할 친구들을 만들어주고
def deposit(self,amount):
self.balance = self.balance+amount
print(
f"Balance after deposit ${amount} to {self.account_name} is {self.balance}"
)
#내가 사용할 도구(함수)를 만들어주고/그 도구 안에서 작용하는
def withdraw(self,amount):
if amount <= self.balance:
self.balance + self.balance - amount
print(
f" balance after withdrawl ${amount} from {self.account_name} is ${self.balance}"
)
else:
print(f"Insufficient funds for withdrawl amount {amount}")
return self.balance
def __str__(self) :
return f'Account name {self.account_name}, Account #:{self.account_number}, Opening Balance {self.balance} Closing balance : ${self.balance}'
#TEST
customer1 = Customer("Sally", "12345", 500.0)
customer1.deposit(75.0)
customer1.withdraw(100)
customer1.__str__()
#Customer.deposit(customer1)
class Bank:
def __init__(self):
self.accounts = []
self.next_account_number = 100
def create_account(self, account_name, opening_balance):
new_account = Customer(
account_name, self.next_account_number, opening_balance
)
self.next_account_number = self.next_account_number + 1 #새로운 계좌를 하나 만들어 줍시다
self.accounts.append(new_account) #새로운 계좌를 계좌리스트에 붙여줍니다
return self.next_account_number - 1 #본래 계좌를 만들었으면 원래대로 제다리에 돌려둡시다
def get_account(self, account_number):
for account in self.accounts:
if account.account_number == account_number :
return account
print("Account not found."
)
return None
def deposit_into(self, account_number, deposit_amount):
found = False
for account in self.accounts:
if account_number == account.account_number:
new_balance = account.deposit(deposit_amount)
found = True
print(
f'Deposit ${deposit_amount} to account #{account_number}, new balance is {new_balance}'
)
if not found:
print(f"Account {account_number} not found")
def calculate_deposit_base(self):
deposit_base = 0
for account in self.accounts:
if account.balance >0:
deposit_base = deposit_base + account.balance
print(f"the total funds after all transaction ${deposit_base}")
return deposit_base
bank = Bank()
John_acount = bank.create_account("John Doe", 900.00)
James_acount = bank.create_account("James Scott", 1200.00)
John_customer = bank.get_account(John_acount)
James_customer = bank.get_account(James_acount)
print(John_customer)
'컴퓨터 공학 > Python' 카테고리의 다른 글
역시 코딩 초보자는 못말려 (0) | 2023.11.15 |
---|---|
Python 기본으로 내가 좋아하는거 갖구 노는중 (0) | 2023.11.14 |
Python Dictionary 와 Set 사용 (0) | 2023.11.14 |
Python 한달 배운 응애의 첫 도전 (0) | 2023.11.07 |
응애 응애 나 파이썬 애기 (0) | 2023.07.03 |