Skip to content

Commit

Permalink
Merge pull request #27 from Kushagra-0801/8-solution
Browse files Browse the repository at this point in the history
Solution to issue 8
  • Loading branch information
the-vampiire authored Oct 8, 2018
2 parents 1394c5c + 2d4ab91 commit 39e1d95
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions beginner/sum-earnings_Kushagra-0801.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"""Solution for Issue #8 (Sum Earnings Challenge)."""


def sum_earnings(finance_data):
"""Validate and process input."""
try:
required_nums = finance_data.count(',') + 1
history = list(map(int, finance_data.split(',')))
if len(history) != required_nums:
raise ValueError
balance = 0
for i in history:
balance += i
if balance < 0:
balance = 0
return balance
except ValueError:
return 0


print(sum_earnings(input()))

0 comments on commit 39e1d95

Please sign in to comment.