<doocs>0227.Basic Calculator II_1.py
def calculate( s: str) -> int:
    num, n = 0, len(s)
    pre_sign = '+'
    stack = []
    for i in range(n):
        if s[i].isdigit():
            num = num * 10 + int(s[i])
        if i == n - 1 or (not s[i].isdigit() and s[i] != ' '):
            if pre_sign == '+':
                stack.append(num)
            elif pre_sign == '-':
                stack.append(-num)
            elif pre_sign == '*':
                stack.append(stack.pop() * num)
            else:
                stack.append(int(stack.pop() / num))
            pre_sign = s[i]
            num = 0
    res = 0
    while stack:
        res += stack.pop()
    return res
def sample_funcname ( var_0 : str ) -> int :
    var_4 , var_6 = 0 , len ( var_0 )
    var_8 = '+'
    var_9 = [ ]
    for var_11 in range ( var_6 ) :
        if var_0 [ var_11 ].isdigit ( ) :
            var_4 = var_4 * 10 + int ( var_0 [ var_11 ] )
        if var_11 == var_6 - 1 or ( not var_0 [ var_11 ].isdigit ( ) and var_0 [ var_11 ] != ' ' ) :
            if var_8 == '+' :
                var_9.append ( var_4 )
            elif var_8 == '-' :
                var_9.append ( - var_4 )
            elif var_8 == '*' :
                var_9.append ( var_9.pop ( ) * var_4 )
            else :
                var_9.append ( int ( var_9.pop ( ) / var_4 ) )
            var_8 = var_0 [ var_11 ]
            var_4 = 0
    var_20 = 0
    while var_9 :
        var_20 += var_9.pop ( )
    return var_20
