Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

We need to write a python code for this exercise, and calculate the number digit

ID: 644338 • Letter: W

Question

We need to write a python code for this exercise, and calculate the number digit by digit

Exercise 2: Add two strings In this exercise, you will write a function called addStrings that takes two strings as parameters and returns the sum of the strings. Each string represents a non-negative integer. For example, Adding these two strings you will get ''265''. Another example is By adding them you will get ''100''. Notice that you need to calculate the sum of two strings character by character. For example, In order to get the actual integer value of a one character string, you can use the ord() function. For example, ''5'' is a one character string and you want to get its actual integer value which is 5. You can use the following code to calculate this. Notice that the encoding of ''5'' is 53, and the ASCII encoding of ''0'' is 48. So you can get 5 by calculating 53 -48. Similarly, you can use the following code to calculate the actual integer value of ''8''. Then write a main function that (1) initializes two variables, each of which is a string representing a non-negative integer, (2) calls the addStrings function and gets the sum of the strings, and (3) prints the return value (i.e., the sum of the strings). Note: directly converting a string into an integer using into is not allowed. That is to say, the following code is NOT allowed.

Explanation / Answer

def addstring(str,str1):

str2=str+str1;

len=(str2+str1)

index=0

r=0

while index <=len:

number[index]=ord(str[index])

number2[index]=ord(str1[index])

l=len(str)

l1=len(str1)

if l>l1

{

i=l

}

else

{

i=l1

}

while index<=i:

sum=number[index]+number1[index]+r

if sum>9

num=sum/10

r=sum%10

result=result+num

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote