human
Calculate sum of the array generated by given operations | Function to find the sum of the array formed by performing given set of operations while traversing the array ops [ ].
If the size of array is 0.
Stores the required sum.
Traverse the array ops [ ].
If the character is C , remove the top element from the stack.
If the character is D , then push 2 * top element into stack.
If the character is + , add sum of top two elements from the stack.
Otherwise , push x and add it to ans.
Print the resultant sum.
Driver Code"
Solution in Python:
 Write me a code to calculate sum of the array generated by given operations and the other steps required?
assistant
#Here is code to calculate sum of the array generated by given operations and the other steps required.
 def findTotalSum ( ops ) :
	if ( len ( ops ) == 0 ) :
		print ( 0 )
		return
	pts = [ ]
	ans = 0
	for i in range ( len ( ops ) ) :
		if ( ops [ i ] == " C " ) :
			ans -= pts [ - 1 ]
			pts . pop ( )
		elif ( ops [ i ] == " D " ) :
			pts . append ( pts [ - 1 ] * 2 )
			ans += pts [ - 1 ]
		elif ( ops [ i ] == " + " ) :
			a = pts [ - 1 ]
			pts . pop ( )
			b = pts [ - 1 ]
			pts . append ( a )
			ans += ( a + b )
			pts . append ( a + b )
		else :
			n = int ( ops [ i ] )
			ans += n
			pts . append ( n )
	print ( ans )
if __name__ == " _ _ main _ _ " :
	arr = [ "5" , " - 2" , " C " , " D " , " + " ]
	findTotalSum ( arr )