-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuser.py
More file actions
32 lines (27 loc) · 1 KB
/
Copy pathuser.py
File metadata and controls
32 lines (27 loc) · 1 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
31
32
class User:
def __init__(self, name, email, password):
self.name = name
self.email = email
self.password = password
self.balance = 0
self.transaction_history = []
def deposit(self, amount):
self.balance += amount
self.transaction_history.append(f"Deposited: {amount}")
def withdraw(self, amount):
if amount <= self.balance:
self.balance -= amount
self.transaction_history.append(f"Withdrawn: {amount}")
else:
print("Insufficient balance!")
def transfer(self, recipient, amount):
if amount <= self.balance:
recipient.deposit(amount)
self.balance -= amount
self.transaction_history.append(f"Transferred: {amount} to {recipient.name}")
else:
print("Insufficient balance!")
def get_balance(self):
return self.balance
def get_transaction_history(self):
return self.transaction_history