Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'Solution' #1478

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion app/main.py
Original file line number Diff line number Diff line change
@@ -1 +1,24 @@
# write your code here
import csv


def create_report(data_file_name: str, report_file_name: str) -> None:
with open(data_file_name, "r") as data_file:
reader = csv.reader(data_file)
total_buy = 0
total_supply = 0
for row in reader:
if not row:
continue
operation_type,amount = row[0], int(row[1])
if operation_type == "supply":
total_supply += amount
if operation_type == "buy":
total_buy += amount

result = total_supply - total_buy

with open(report_file_name, "w", newline="") as report_file:
writer = csv.writer(report_file)
writer.writerow(["supply",total_supply])
writer.writerow(["buy", total_buy])
writer.writerow(["result", result])
22 changes: 11 additions & 11 deletions apples.csv
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
supply,30
buy,10
buy,13
supply,17
buy,10
supply,5
supply,80
buy,39
supply,56
buy,32
buy,11
supply,30
buy,10
buy,13
supply,17
buy,10
supply,5
supply,80
buy,39
supply,56
buy,32
buy,11
30 changes: 15 additions & 15 deletions bananas.csv
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
buy,10
supply,300
buy,130
buy,12
supply,20
buy,1
supply,50
supply,12
supply,8
buy,41
supply,10
buy,12
buy,10
buy,77
supply,91
buy,10
supply,300
buy,130
buy,12
supply,20
buy,1
supply,50
supply,12
supply,8
buy,41
supply,10
buy,12
buy,10
buy,77
supply,91
26 changes: 13 additions & 13 deletions grapes.csv
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
supply,78
buy,9
buy,17
buy,22
supply,27
buy,80
supply,51
supply,82
buy,49
supply,102
supply,12
buy,29
buy,146
supply,78
buy,9
buy,17
buy,22
supply,27
buy,80
supply,51
supply,82
buy,49
supply,102
supply,12
buy,29
buy,146
22 changes: 11 additions & 11 deletions oranges.csv
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
buy,19
supply,33
buy,37
supply,170
buy,80
supply,44
supply,31
buy,3
supply,17
buy,6
buy,9
buy,19
supply,33
buy,37
supply,170
buy,80
supply,44
supply,31
buy,3
supply,17
buy,6
buy,9