forked from mirunici007/Budget-Manager
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuget.py
More file actions
37 lines (30 loc) · 1.08 KB
/
Copy pathbuget.py
File metadata and controls
37 lines (30 loc) · 1.08 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
class Budget:
def __init__(self):
self.transactions = []
def add_transaction(self, transaction_type, amount, description =""):
types = {"income", "expense"}
if transaction_type not in types:
return False
if amount < 0:
return False
self.transactions.append({"type": transaction_type, "amount": amount, "description": description})
return True
def income(self):
sum_inc = 0
for transaction in self.transactions:
if transaction["type"] == "income":
sum_inc += transaction["amount"]
return sum_inc
def expense(self):
sum_exp = 0
for transaction in self.transactions:
if transaction["type"] == "expense":
sum_exp += transaction["amount"]
return sum_exp
def available_budget(self):
sum_inc = self.income()
sum_exp = self.expense()
available = sum_inc - sum_exp
return available
def get_transactions(self):
return self.transactions.copy()