Skip to content

Commit

Permalink
Update calculator.py
Browse files Browse the repository at this point in the history
  • Loading branch information
ftm-2005 authored Jun 5, 2024
1 parent 1c3782d commit a880e0a
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,20 @@
'3'
"""
def add(s: str) -> str:
sum = 0
if (s == ""):
return "0"
s = s.replace('\n', ',')
L = s.split(",")
for i in range(len(L)):
if "." in L[i]:
sum += float(L[i])
else:
sum += int(L[i])
return str(sum)
if (s[-1] == ',' or s[-1] == '\n'){
return 'Number expected but EOF found.'
}
sum = 0
if (s == ""):
return "0"
s = s.replace('\n', ',')
L = s.split(",")
for i in range(len(L)):
if "." in L[i]:
sum += float(L[i])
else:
sum += int(L[i])
return str(sum)



Expand Down

0 comments on commit a880e0a

Please sign in to comment.