-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpound_penny_foolish.py
139 lines (97 loc) · 4.11 KB
/
pound_penny_foolish.py
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#This is the actual budget tracker in which multiple modules will run.
#Open csv file
with open("BankStatement.csv.txt", "r") as f:
file_data = f.read()
database = {}
temp_input = file_data.replace("\n", ",")
cost_input = temp_input.split(",")
count = len(cost_input)-1
a = 0
b = 0
for x in range(3, count, 3):
a = x
b = x + 2
category = cost_input[b]
if (x + 2) > count:
continue
else:
if category not in database:
database[category] = cost_input[a:b]
else:
database[category] = database[category] + cost_input[a:b]
# functionality of this module = ask for budget, save budget and print budget
budget_command = "Provide your budget for this month:"
print(budget_command)
budget = input()
result_total_expense = 0
print("Thank you. Your budget for this month is {} GBP.".format(budget))
start_module = "\nThe following commands are valid: \nEnter, will allow you to add data to your expense database; \nDownload, will download a report including your latest expenses by category; \nRemaining, will calculate and print your remaining budget; \nPound, will calculate if you are 'Pound foolish' or 'Penny foolish. \n"
add_costs_command = "When adding your cost to the database, please use the following format: category, name, -amount."
print(start_module)
print(add_costs_command)
command = "\nWhat would you like to do?"
while True:
print(command)
total_expense = []
user_input = input().split(",")
if user_input[0] == "Enter":
category = user_input[1]
if category not in database:
database[category] = user_input[2:4]
#Should the amounts be summed by name too?
else:
database[category] = database[category] + user_input[2:4]
elif user_input[0] == "Download":
for category in database:
list_amount = []
if category == "INCOME":
for x in range(len(database[category])):
if x % 2 == 0:
continue
else:
list_amount.append(float(database[category][x]))
result = sum(list_amount)
else:
for x in range(len(database[category])):
if x % 2 == 0:
continue
else:
list_amount.append(float(database[category][x]))
total_expense.append(float(database[category][x]))
result = sum(list_amount)*-1
result_total_expense = sum(total_expense)*-1
print("Your total expense for %s is %.2f GBP." % (category, result))
print("Your total expense for this month is %.2f GBP." % (result_total_expense))
elif user_input[0] == "Remaining":
income_amount = []
for x in range(len(database["INCOME"])):
if x % 2 == 0:
continue
else:
income_amount.append(float(database["INCOME"][x]))
result_income = sum(income_amount)
remaining_budget = float(budget) - float(result_total_expense) + float(result_income)
print("Your remaining budget for this month is %.2f GBP." % (remaining_budget))
elif user_input[0] == "Pound":
pound_penny = []
pound_foolish = []
penny_foolish = []
for new_category in database:
for y in range(len(database[new_category])):
if y % 2 == 0:
continue
else:
pound_penny.append(float(database[new_category][y]))
for amount in range(len(pound_penny)):
if pound_penny[amount] < 10:
penny_foolish.append(pound_penny[amount])
else:
pound_foolish.append(pound_penny[amount])
result_penny = sum(penny_foolish)
result_pound = sum(pound_foolish)
if result_penny > result_pound:
print("You are penny foolish!")
else:
print("You are pound foolish!")
else:
print("This command is invalid, please try again.")