forked from the-vampiire/hacktoberithms
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
20 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |