Skip to content

Commit

Permalink
the-vampiire#8 solution
Browse files Browse the repository at this point in the history
  • Loading branch information
dsargento committed Oct 12, 2018
1 parent 0a01dce commit 42df591
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions beginner/sum-earnings_dsargento.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
def sum_earnings(input):
earnings_list = input.split(',')
earnings = 0
spendings = 0
for val in earnings_list:
try:
val = int(val)
except ValueError:
return 0
if val >= 0:
earnings += val
else:
spendings += val
if earnings < (spendings * -1):
spendings = 0
earnings = 0
val_sum = spendings + earnings
if val_sum < 0:
return 0
return val_sum

0 comments on commit 42df591

Please sign in to comment.