human
Sum of two large numbers | Function for finding sum of larger numbers.
Before proceeding further , make sure length of str2 is larger ..
Take an empty string for storing result.
Calculate length of both string.
Reverse both of strings.
Do school mathematics , compute sum of current digits and carry.
Calculate carry for next step.
Add remaining digits of larger number.
Add remaining carry.
reverse resultant string.
Driver code"
How can the above be solved in Python?
assistant
#Here is code to sum of two large numbers and the other steps required.
 def findSum ( str1 , str2 ) :
	if ( len ( str1 ) > len ( str2 ) ) :
		t = str1 ;
		str1 = str2 ;
		str2 = t ;
	str = " " ;
	n1 = len ( str1 ) ;
	n2 = len ( str2 ) ;
	str1 = str1 [ : : - 1 ] ;
	str2 = str2 [ : : - 1 ] ;
	carry = 0 ;
	for i in range ( n1 ) :
		sum = ( ( ord ( str1 [ i ] ) - 48 ) + ( ( ord ( str2 [ i ] ) - 48 ) + carry ) ) ;
		str += chr ( sum % 10 + 48 ) ;
		carry = int ( sum / 10 ) ;
	for i in range ( n1 , n2 ) :
		sum = ( ( ord ( str2 [ i ] ) - 48 ) + carry ) ;
		str += chr ( sum % 10 + 48 ) ;
		carry = ( int ) ( sum / 10 ) ;
	if ( carry ) :
		str += chr ( carry + 48 ) ;
	str = str [ : : - 1 ] ;
	return str ;
str1 = "12" ;
str2 = "198111" ;
print ( findSum ( str1 , str2 ) ) ;