-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCheckbook-App.py
More file actions
88 lines (62 loc) · 2.58 KB
/
Checkbook-App.py
File metadata and controls
88 lines (62 loc) · 2.58 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
import json
import datetime
with open("user_data_timestamp.json", 'r') as f:
userBalance = json.load(f)
def currentBalance(userBalance):
print(f"\nYour current balance is: ${'{:.2f}'.format(round(sum(list(userBalance.values())) , 2))}")
def history(userBalance):
with open("user_data_timestamp.json" , 'w') as f:
json.dump(userBalance,f)
print(f"\nThis is your transaction history for your last {len(userBalance)} transactions.\n")
for a, b in userBalance.items():
print(f"{a} ${'{:.2f}'.format(b)}")
def withdraw(userBalance):
userInput = ""
x = datetime.datetime.now()
while userInput != userInput.isdigit():
userInput=input("How much would you like to withdraw? $")
if userInput.isalpha():
print("\nSorry you must enter numbers only.\n")
else:
userInput=-1*float(userInput)
userBalance.update({x.strftime("%b-" "%d-" "%Y" " %I:" "%M:" "%S" " %p"): userInput})
break
print(f"\nYour new blance is: ${'{:.2f}'.format(round(sum(list(userBalance.values())) , 2))}")
with open("user_data_timestamp.json", 'w') as f:
json.dump(userBalance,f)
def deposit(userBalance):
userInput = ""
x = datetime.datetime.now()
while userInput != userInput.isdigit():
userInput=input("How much would you like to deposit? $")
if userInput.isalpha():
print("\nSorry, you must enter numbers only.\n")
else:
userInput=float(userInput)
userBalance.update({x.strftime("%b-" "%d-" "%Y" " %I:" "%M:" "%S" " %p"): userInput})
break
print(f"\nYour new blance is: ${'{:.2f}'.format(round(sum(list(userBalance.values())) , 2))}")
with open("user_data_timestamp.json", 'w') as f:
json.dump(userBalance,f)
userReply = ""
while userReply != "5":
print("""\n~~~ Welcome to your terminal checkbook! ~~~\n
What would you like to do?
1) view current balance
2) record a debit (withdraw)
3) record a credit (deposit)
4) transaction history
5) exit\n""")
userReply = input("Your choice? ")
if userReply == "1":
currentBalance(userBalance)
elif userReply == "2":
withdraw(userBalance)
elif userReply == "3":
deposit(userBalance)
elif userReply == "4":
history(userBalance)
elif userReply == "5":
print("\nHave a nice day.\n")
else:
print("\nSorry invalid choice.")