Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 25e45b9

Browse files
authored
str
1 parent f2092e3 commit 25e45b9

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

Functions/str_addition.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
def addition(s1,s2):
2+
s1 = s1[::-1]
3+
s2 = s2[::-1]
4+
s3 = ""
5+
carry = 0
6+
for i in range (len(s1)):
7+
d1 = int(s1[i])
8+
d2 = int(s2[i]) if i < len(s2) else 0
9+
total = d1 + d2 + carry
10+
carry = total//10
11+
s3 += str(total%10)
12+
if carry:
13+
s3 += str(carry)
14+
s3 = s3[::-1]
15+
return s3
16+
s1 = input()
17+
s2 = input()
18+
if len(s2) > len(s1):
19+
s1, s2 = s2, s1
20+
s3 = addition(s1,s2)
21+
print(s3)

0 commit comments

Comments
 (0)