diff --git a/beginner/sum-earnings_Kushagra-0801.py b/beginner/sum-earnings_Kushagra-0801.py new file mode 100644 index 0000000..7c661fd --- /dev/null +++ b/beginner/sum-earnings_Kushagra-0801.py @@ -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()))