-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathEval_Scratch.py
44 lines (42 loc) · 987 Bytes
/
Eval_Scratch.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
def addStrings(num1: str, num2: str) -> str:
n1=len(num1)
n2=len(num2)
carry=0
x=0
sum=''
i=n1-1
j=n2-1
while(i>=0 and j>=0):
x=int(num1[i])+ int(num2[j])+carry
if(x>9):
sum=str(x%10) + sum
carry=1
else:
carry=0
sum= str(x) + sum
i-=1
j-=1
if(i>=0):
while(i>=0):
x=int(num1[i]) + carry
if(x>9):
sum =str(x%10) + sum
carry=1
else:
carry=0
sum =str(x) + sum
i-=1
if(j>=0):
while(j>=0):
x=int(num2[j]) + carry
if(x>9):
sum =str(x%10) + sum
carry=1
else:
carry=0
sum =str(x) + sum
j-=1
if(carry==1):
sum= str(carry)+sum
return sum
print(addStrings('2321','3'))