-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbanking.py
39 lines (30 loc) · 1.21 KB
/
banking.py
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
31
32
33
34
35
36
37
38
39
class Account:
def __init__(self, name, account_number, balance):
self.name = name
self.account_number = account_number
self.balance = balance
def deposit(self, amount):
self.balance += amount
print(f"{self.name} Deposited {amount} $. Current balance is: {self.balance}")
def withdraw(self, amount):
if self.balance >= amount:
self.balance -= amount
print(f"{self.name} Withdrew {amount} $. Current balance is: {self.balance}")
else:
print("You don't have enough funds to withdraw.")
class Savings_Account(Account):
def __init__(self, name, account_number, balance, interest_rate):
super().__init__(name, account_number, balance)
self.interest_rate = interest_rate
def add_interest(self):
interest = self.balance * self.interest_rate
self.deposit(interest)
account1 = Account("John Doe", "123456", 1000)
account1.deposit(500)
account1.withdraw(200)
print()
savings_account = Savings_Account("John Doe", "789012", 2000, 0.05)
savings_account.deposit(1000)
savings_account.add_interest()
savings_account.withdraw(500)
savings_account.withdraw(1000)