From 8c3b3068313b27355458e634c7efa675900580f2 Mon Sep 17 00:00:00 2001 From: Kushagra Gupta Date: Fri, 5 Oct 2018 11:39:37 +0530 Subject: [PATCH] Solution to issue 8 --- beginner/sum-earnings_Kushagra-0801.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 beginner/sum-earnings_Kushagra-0801.py diff --git a/beginner/sum-earnings_Kushagra-0801.py b/beginner/sum-earnings_Kushagra-0801.py new file mode 100644 index 0000000..1eab79c --- /dev/null +++ b/beginner/sum-earnings_Kushagra-0801.py @@ -0,0 +1,16 @@ +"""Solution for Issue #8 (Sum Eanings 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')