Skip to content

Commit d2675a7

Browse files
authored
Merge pull request #134 from AnilKumarTeegala/patch-1
Solved Sum Earnings #8
2 parents dc386e0 + e13b577 commit d2675a7

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
def Sum_Earnings(earnings):
2+
total_earnings=0 # Initialise total earnings to zero
3+
for money in earnings:
4+
if money < 0 and money + total_earnings < 0: #if sold+bought<0 and day_earnings<0
5+
total_earnings = 0 #then assign total_earnings to zero
6+
else: #
7+
total_earnings += money # else add day_earnings to total_earnings
8+
return total_earnings # return total_earnings
9+
10+
inp=input().split(',') # input taken as comma separated string and converted into list
11+
try:
12+
intInp = list(map(lambda x:int(x),inp)) # Converted list of String integers to Integers, if any alphabets got it catches the ValueError
13+
print(Sum_Earnings(intInp)) # if input contains all the string of integers then it goes to calculate total_earnings
14+
except ValueError:
15+
print(0) # if input contains any albhabets then total earnings is Zero

0 commit comments

Comments
 (0)