-
Notifications
You must be signed in to change notification settings - Fork 0
/
bank_account.py
54 lines (47 loc) · 1.91 KB
/
bank_account.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import random
class BankAccount:
def __init__(self, name, email, address, account_type):
self.name = name
self.email = email
self.address = address
self.account_type = account_type
self.balance = 0
self.account_number = random.randint(1000, 9999)
self.transaction_history = []
self.loan_limit = 2
self.loan_taken = 0
def deposit(self, amount):
if amount > 0:
self.balance += amount
self.transaction_history.append(f"Deposited Rs{amount}")
return f"Rs{amount} deposited successfully."
else:
return "Invalid deposit amount."
def withdraw(self, amount):
if amount <= self.balance:
self.balance -= amount
self.transaction_history.append(f"Withdrew Rs{amount}")
return f"Rs{amount} withdrawn successfully."
else:
return "Withdrawal amount exceeded."
def check_balance(self):
return f"Available balance: Rs{self.balance}"
def check_transaction_history(self):
return self.transaction_history
def take_loan(self, amount):
if self.loan_limit > 0:
self.balance += amount
self.loan_taken += amount
self.loan_limit -= 1
self.transaction_history.append(f"Loan taken: Rs{amount}")
return f"Loan of Rs{amount} taken successfully."
else:
return "You have reached the maximum loan limit."
def transfer(self, target_account, amount):
if self.balance >= amount:
self.balance -= amount
target_account.balance += amount
self.transaction_history.append(f"Transferred Rs{amount} to account {target_account.account_number}")
return f"Rs{amount} transferred to account {target_account.account_number} successfully."
else:
return "Insufficient balance for the transfer."