human
What is a code to sum of all substrings of a string representing a number and the other steps required given the following:
Sum of all substrings of a string representing a number | Set 1 | Returns sum of all substring of num.
allocate memory equal to length of string.
initialize first value with first digit.
loop over all digits of string.
update each sumofdigit from previous value.
add current value to the result.
Driver code"
How can the above be solved in Python?
assistant
#Here is code to sum of all substrings of a string representing a number and the other steps required.
 def sumOfSubstrings ( num ) :
	n = len ( num )
	sumofdigit = [ ]
	sumofdigit . append ( int ( num [ 0 ] ) )
	res = sumofdigit [ 0 ]
	for i in range ( 1 , n ) :
		numi = int ( num [ i ] )
		sumofdigit . append ( ( i + 1 ) * numi + 10 * sumofdigit [ i - 1 ] )
		res += sumofdigit [ i ]
	return res
num = "1234"
print ( sumOfSubstrings ( num ) )