-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaccount.py
More file actions
49 lines (39 loc) · 1.57 KB
/
account.py
File metadata and controls
49 lines (39 loc) · 1.57 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import time
import pandas as pd
class Account:
def __init__(self, owner, balance):
self.owner = owner
self.balance = balance
self.transactions = pd.DataFrame(columns=['category', 'amount'])
def __str__(self):
return f"Account Owner: {self.owner}\nCurrent Balance: $ {self.balance}"
def deposit(self, amount):
if not isinstance(amount, (int, float)):
return "Transaction must be a number; deposit failed."
self.dep = pd.DataFrame({
'category': ['Deposit'],
'amount': [amount]
}, index=[0])
self.transactions = pd.concat([self.transactions, self.dep], ignore_index=True)
self.balance += amount
print('Deposit accepted...')
time.sleep(1)
print(f"Current Balance $ {self.balance}")
def withdraw(self, amount):
if not isinstance(amount, (int, float)):
return "Transaction must be a number; withdraw failed."
elif amount > self.balance:
return f"Withdrawal amount greater than available balance ($ {self.balance})."
self.wth = pd.DataFrame({
'category': ['Withdraw'],
'amount': [-amount]
}, index=[0])
self.transactions = pd.concat([self.transactions, self.wth], ignore_index=True)
self.balance -= amount
print('Withdrawal accepted...')
time.sleep(1)
print(f"Current Balance $ {self.balance}")
def get_transactions(self):
return self.transactions
def get_balance(self):
return f"$ {self.balance}"