human
Can you provide 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.
storing prev value.
substrings sum upto current index loop over all digits of string.
update each sumofdigit from previous value.
add current value to the result.
prev = current update previous.
Driver code to test above methods"
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 )
	prev = int ( num [ 0 ] )
	res = prev
	current = 0
	for i in range ( 1 , n ) :
		numi = int ( num [ i ] )
		current = ( i + 1 ) * numi + 10 * prev
		res += current
	return res
num = "1234"
print ( sumOfSubstrings ( num ) )