-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbank.py
More file actions
30 lines (26 loc) · 1.05 KB
/
bank.py
File metadata and controls
30 lines (26 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# This is a simple implementation of a bank account class in Python. It includes methods for depositing, withdrawing, and checking the balance of the account.
class BankAccount:
def __init__(self, account_number, balance=0):
self.account_number = account_number
self.balance = balance
def deposit(self, amount):
if amount > 0:
self.balance += amount
print(f"Deposited ${amount}. New balance: ${self.balance}")
else:
print("Deposit amount must be positive.")
def withdraw(self, amount):
if amount > 0:
if self.balance >= amount:
self.balance -= amount
print(f"Withdrew ${amount}. New balance: ${self.balance}")
else:
print("Insufficient funds.")
else:
print("Withdrawal amount must be positive.")
def get_balance(self):
return self.balance
account = BankAccount("123456789", 1000)
account.deposit(500)
account.withdraw(200)
print("Current Balance:", account.get_balance())