Skip to content

Commit

Permalink
Merge pull request #77 from dbourdeveloper/8-solution
Browse files Browse the repository at this point in the history
Beginner Problem #8 Solution
  • Loading branch information
the-vampiire authored Oct 8, 2018
2 parents f39154c + e9a0205 commit 6f78a44
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions beginner/sum-earnings_david.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
def sum_earnings(input):
streak_sum = 0
try:
streak = list(map(int, input.split(',')))
for num in streak:
if num < 0 and num + streak_sum < 0:
streak_sum = 0
else:
streak_sum += num
except ValueError:
return 0
return streak_sum

assert(sum_earnings('1,3,-2,1,2') == 5)
assert(sum_earnings('0,7,0,2,-12,3,0,2') == 5)
assert(sum_earnings('0,0,0,0,0') == 0)
assert(sum_earnings('qwerty') == 0)
assert(sum_earnings(',,3,,4') == 0)
assert(sum_earnings('1,2,v,b,3') == 0)

0 comments on commit 6f78a44

Please sign in to comment.