human
Calculate score of parentheses from a given string | Function to calculate the score of the parentheses using stack.
To keep track of the score.
Initially , push 0 to stack.
Traverse the string s.
If ' ( ' is encountered , then push 0 to stack.
Otherwise.
Balance the last ' ( ' , and store the score of inner parentheses.
If tmp is not zero , it means inner parentheses exists.
Otherwise , it means no inner parentheses exists.
Pass the score of this level to parent parentheses.
Print the score.
Driver Code.
Function call"
How can the above be solved in Python?

=====
Can you provide a code to calculate score of parentheses from a given string and the other steps required?
assistant
#Here is code to calculate score of parentheses from a given string and the other steps required.
 def scoreOfParentheses ( s ) :
	stack = [ ]
	stack . append ( 0 )
	for c in s :
		if ( c == ' ( ' ) :
			stack . append ( 0 )
		else :
			tmp = stack [ len ( stack ) - 1 ]
			stack = stack [ : - 1 ]
			val = 0
			if ( tmp > 0 ) :
				val = tmp * 2
			else :
				val = 1
			stack [ len ( stack ) - 1 ] += val
	print ( stack [ len ( stack ) - 1 ] )
if __name__ == ' _ _ main _ _ ' :
	S = " ( ( ) ( ( ) ) ) "
	scoreOfParentheses ( S )