Skip to content

Commit b092dd1

Browse files
committed
Pybank running fine
1 parent 9fcbfd3 commit b092dd1

File tree

3 files changed

+49
-36
lines changed

3 files changed

+49
-36
lines changed

PyBank/budget_analysis.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
Financial Analysis
3+
----------------------------
4+
Total Months: 86
5+
Total: $38382578
6+
Average Change: $-2315.12
7+
Greatest Increase in Profits: Feb-2012 ($1926159)
8+
Greatest Decrease in Profits: Sep-2013 ($-2196167)

PyBank/main.py

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,55 +8,58 @@
88
change_list = []
99
total_change = 0
1010
months = []
11-
total_m = 0
12-
net_total=0
11+
total_m = 1
12+
net_total= 0
13+
file_to_output = os.path.join("budget_analysis.txt")
1314

1415

1516
budget_csv = os.path.join('.','Resources','budget_data.csv')
1617
with open(budget_csv, 'r') as csvfile:
1718
csvreader = csv.reader(csvfile, delimiter=',')
1819
header = next(csvreader)
19-
previous_row = next(csvreader)
20+
first_row = next(csvreader)
21+
previous_row = int(first_row[1])
22+
net_total = int(first_row[1])
23+
2024
for row in csvreader:
2125

2226
net_total+=int(row[1])
2327
total_m = total_m+1
24-
change_value = int(row[1]-previous_row)
28+
current_value = int(row[1])
29+
30+
change_value = int(current_value-previous_row)
2531

2632
change_list.append(change_value)
2733
months.append(row[0])
28-
previous_row = row
34+
previous_row = int(row[1])
2935

3036
total_change = total_change + change_value
3137
if change_value > greatest_increase[1]:
3238
greatest_increase[0] = str(row[0])
3339
greatest_increase[1] = change_value
3440

41+
3542
if change_value < greatest_decrease[1]:
3643
greatest_decrease[0] = str(row[0])
3744
greatest_decrease[1] = change_value
3845

3946

40-
print (total_change)
41-
print(net_total)
42-
print (total_m)
43-
avg_change = total_change/len(months)
44-
print(avg_change)
45-
47+
avg_change = total_change/len(months)
48+
49+
output = (
50+
f"\nFinancial Analysis\n"
51+
f"----------------------------\n"
52+
f"Total Months: {total_m}\n"
53+
f"Total: ${net_total}\n"
54+
f"Average Change: ${avg_change:.2f}\n"
55+
f"Greatest Increase in Profits: {greatest_increase[0]} (${greatest_increase[1]})\n"
56+
f"Greatest Decrease in Profits: {greatest_decrease[0]} (${greatest_decrease[1]})\n")
57+
58+
with open(file_to_output, "w") as txt_file:
59+
txt_file.write(output)
60+
61+
file_to_output
4662

47-
print("Financial Analysis")
48-
49-
print("--------------------------")
50-
51-
print(f"Total Months:{str(total_m)}")
52-
53-
print(f"Total:{int(net_total)}")
54-
55-
print(f"Average_change : {int(avg_change)}")
56-
57-
print(f"Greatest Increase in profit:{ greatest_increase('['+str(row)+']') + change_value}")
58-
59-
print(f"Greatest Decrease in profit:{ greatest_decrease('['+str(row)+']') + change_value}")
6063

6164

6265

PyPoll/main.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33

44
candidates = {}
55

6+
#file_to_output = os.path.join("poll_analysis.txt")
7+
68
# Path to collect data from the Resources folder
7-
budget_csv = os.path.join('.','Resources','election_data.csv')
8-
with open(budget_csv, 'r') as csvfile:
9+
election_csv = os.path.join('.','Resources','election_data.csv')
10+
with open(election_csv, 'r') as csvfile:
911

1012
csvreader = csv.reader(csvfile, delimiter=',')
1113
header = next(csvreader)
@@ -16,17 +18,17 @@
1618
else:
1719
candidates[row[2]] = 1
1820

19-
total_votes = sum(candidates.values())
20-
total_votes
21-
21+
total = candidates.values()
22+
total_votes = sum(total)
23+
2224
list_candidates = candidates.keys()
23-
list_candidates
25+
2426
votes_per = [f'{(x/total_votes)*100:.3f}%' for x in candidates.values()]
25-
votes_per
26-
winner = list(candidates.keys())[candidates.values()(max(candidates.values()))]
27-
winner
28-
27+
2928

29+
winner = list(candidates.keys())[list(candidates.values()).index(max(candidates.values()))]
30+
winner
31+
3032
print("Election results")
3133

3234
print("--------------------------")
@@ -35,11 +37,11 @@
3537

3638
print("-----------------------------")
3739

38-
print(f'{candidates[list_candidates]}":"{candidates[votes_per]}"("{candidates[candidates.values()]}'")")
40+
print(f'{candidates(str["list_candidates"])":" ["votes_per"] "% (" ["total"]}'")")
3941

4042
print("-------------------------------")
4143

42-
print(f'Winner: {str(winner)}')
44+
print(f'Winner: {candidates(winner)}')
4345

4446

4547

0 commit comments

Comments
 (0)