-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheckbook_updated.py
More file actions
114 lines (94 loc) · 3.44 KB
/
Copy pathcheckbook_updated.py
File metadata and controls
114 lines (94 loc) · 3.44 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import datetime
def current_balance():
with open('checkbook_history.txt') as f:
bal = int(f.readline())
print("Available Balance is:", bal)
return bal
def deposit(balance):
amount = int(input("How much would you like to deposit? "))
balance += amount
with open('checkbook_history.txt', 'a') as f:
timestamp = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
f.write(f"Deposit\t{timestamp}\t{amount}\n")
return balance
def withdrawal(balance):
amount = int(input("How much would you like to withdraw? "))
if amount <= balance:
balance -= amount
with open('checkbook_history.txt', 'a') as f:
timestamp = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
f.write(f"Withdrawal\t{timestamp}\t{amount}\n")
else:
print("Insufficient balance.")
return balance
def view_transactions():
with open('checkbook_history.txt') as f:
transactions = f.readlines()[1:] # Skip the first line (balance)
for transaction in transactions:
print(transaction.strip())
def view_transactions_by_category(category):
with open('checkbook_history.txt') as f:
transactions = f.readlines()[1:] # Skip the first line (balance)
for transaction in transactions:
details = transaction.strip().split('\t')
if details[0].lower() == category.lower():
print(transaction.strip())
def search_transactions(keyword):
with open('checkbook_history.txt') as f:
transactions = f.readlines()[1:] # Skip the first line (balance)
for transaction in transactions:
if keyword.lower() in transaction.lower():
print(transaction.strip())
def modify_transaction():
# Provide the implementation to modify a past transaction
pass
def main():
print("~~~~~~~~~ HELLO, WELCOME BACK! ~~~~~~~~~")
bal = current_balance() # Initialize bal with the current balance
while True:
print("Please select an option:")
print("1. View Current Balance")
print("2. Make a Withdrawal")
print("3. Make a Deposit")
print("4. View All Transactions")
print("5. View Transactions by Category")
print("6. Search Transactions")
print("7. Modify a Past Transaction")
print("8. Exit")
choice = input("Choice? ")
print()
if choice == "1":
current_balance()
print()
elif choice == "2":
bal = withdrawal(bal)
current_balance()
print()
elif choice == "3":
bal = deposit(bal)
current_balance()
print()
elif choice == "4":
view_transactions()
print()
elif choice == "5":
category = input("Enter a category: ")
view_transactions_by_category(category)
print()
elif choice == "6":
keyword = input("Enter a keyword: ")
search_transactions(keyword)
print()
elif choice == "7":
modify_transaction()
print()
elif choice == "8":
print("THANK YOU, HAVE A GREAT DAY!")
with open('checkbook_history.txt', 'w') as f:
f.write(str(bal) + '\n') # Write the balance as the first line
break
else:
print("PLEASE SELECT OPTIONS 1 THROUGH 8")
print()
if __name__ == '__main__':
main()