diff --git a/beginner/sum-earnings_Kushagra-0801.py b/beginner/sum-earnings_Kushagra-0801.py index 1eab79c..7c661fd 100644 --- a/beginner/sum-earnings_Kushagra-0801.py +++ b/beginner/sum-earnings_Kushagra-0801.py @@ -1,16 +1,21 @@ -"""Solution for Issue #8 (Sum Eanings Challenge).""" +"""Solution for Issue #8 (Sum Earnings Challenge).""" -try: - input_ = input() - required_nums = input_.count(',') + 1 - history = list(map(int, input_.split(','))) - if len(history) != required_nums: - raise ValueError - balance = 0 - for i in history: - balance += i - if balance < 0: - balance = 0 - print(balance) -except ValueError: - print('0') + +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()))