Go: package main

import (
	"bufio"
	"fmt"
	"go/token"
	"go/types"
	"os"
	"strconv"
	"strings"
)

func main() {
	stdin := bufio.NewScanner(os.Stdin)
	stdin.Scan()
	n, _ := strconv.Atoi(stdin.Text())
	for i := 0; i < n; i++ {
		stdin.Scan()
		exp := strings.TrimRight(stdin.Text(), "=")
		res, _ := types.Eval(token.NewFileSet(), nil, token.NoPos, exp)
		fmt.Println(res.Value)
	}
}

Python: def getLR(li):
    l, r = 0, 0
    for i in range(len(li)):
        if li[i] == "(":
            l = i
        if li[i] == ")":
            r = i + 1
            return l, r
    return l, r

def calc(li):
    # *, /
    t_li = []
    while True:
        for i in range(len(li) - 2):
            if li[i + 1] == "*":
                t_li = li[:i] + [li[i] * li[i + 2]] + li[i + 3:]
                li = list(t_li)
                break
            elif li[i + 1] == "/":
                t_li = li[:i] + [li[i] // li[i + 2]] + li[i + 3:]
                li = list(t_li)
                break
        else:
            # no update
            break

    # +, -
    while True:
        for i in range(len(li) - 2):
            if li[i + 1] == "+":
                t_li = li[:i] + [li[i] + li[i + 2]] + li[i + 3:]
                li = list(t_li)
                break
            elif li[i + 1] == "-":
                t_li = li[:i] + [li[i] - li[i + 2]] + li[i + 3:]
                li = list(t_li)
                break
        else:
            break

    return t_li


n = int(input())
for _ in range(n):
    s = input()[:-1]

    s = "#(" + s + ")#"
    li = []
    number = ""
    for i in range(len(s)):
        if s[i].isdigit():
            number += s[i]
        else:
            if number != "":
                li.append(int(number))
                number = ""
            li.append(s[i])

    while True:
        l, r = getLR(li)

        if r == 0:
            break

        li = li[:l] + calc(li[l + 1 : r - 1]) + li[r:]

    print(li[1])

Python: import sys

input()
for i in sys.stdin.readlines():
        print(eval(i[:-2].replace('/', '//')))

Python: from collections import deque
from sys import stderr
from functools import reduce
from operator import add
def f(): return [int(i) for i in input().split()]
def debug(*x, sep=" ", end="\n"):
    for item in x:
        stderr.write(repr(item))
        stderr.write(sep)
    stderr.write(end)


def eva(l, r, op):
    if op == "+":
        return l + r
    elif op == "-":
        return l - r
    elif op == "*":
        return l * r
    elif op == "/":
        return l // r


def calc(exp):
    i = 0
    num = deque()
    ops = deque()
    ope = ""
    while i < len(exp):
        if exp[i] == '(':
            end = exp[i:].rfind(")")
            num.append(calc(exp[i+1:i+end]))
            i += end + 1
            if ope:
                l = num.pop()
                r = num.pop()
                num.append(eva(l, r, ope))
                ope = ""
        elif exp[i].isnumeric():
            num.append(int(exp[i]))
            if ope:
                num.append(eva(num.pop(), num.pop(), ope))
                ope = ""
        elif exp[i] in ["*", "/"]:
            ope = exp[i]
        elif exp[i] in ["+", "-"]:
            ops.append(exp[i])
        elif exp[i] == "=":
            break
        i += 1
    while len(ops) != 0:
        l = num.popleft()
        r = num.popleft()
        num.appendleft(eva(l,r,ops.popleft()))
    
    debug(exp, num)
    return num[0]


n = int(input())
for i in range(n):
    exp = input()
    print(calc(exp))

Python: from collections import deque
def eva(l, r, op):
    if op == "+":
        return l + r
    elif op == "-":
        return l - r
    elif op == "*":
        return l * r
    elif op == "/":
        return l // r


def calc(exp):
    i = 0
    num = deque()
    ops = deque()
    ope = ""
    while i < len(exp):
        if exp[i] == '(':
            end = exp[i + 1:].index(")")
            num.append(calc(exp[i + 1:i + 1 + end]))
            i += end
            if ope:
                num.append(eva(num.pop(), num.pop(), ope))
                ope = ""
        if exp[i].isnumeric():
            num.append(int(exp[i]))
            if ope:
                num.append(eva(num.pop(), num.pop(), ope))
                ope = ""
        elif exp[i] in ["*", "/"]:
            ope = exp[i]
        elif exp[i] in ["+", "-"]:
            ops.append(exp[i])
        elif exp[i] == "=":
            break
        i += 1
    while len(ops) != 0:
        l = num.popleft()
        r = num.popleft()
        num.appendleft(eva(l,r,ops.popleft()))
    return num[0]


n = int(input())
for i in range(n):
    exp = input()
    print(calc(exp))

Python: from collections import deque

def eva(l, r, op):
    if op == "+":
        return l + r
    elif op == "-":
        return l - r
    elif op == "*":
        return l * r
    elif op == "/":
        return l // r


def calc(exp,brac=None):
    i = 0 # ループカウンタ?
    num = deque() # 数字をためておく
    ops = deque() # +-をためておく
    ope = "" # */を保存
    
    if not brac:
        # 対応する括弧の位置を記録しておいて計算量を削減
        brac = [-1 for j in range(len(exp))]
        tmpbrac = []
        for j in range(len(exp) - 1, 0, -1):
            if exp[j] == ')':
                tmpbrac.append(j)
            elif exp[j] == '(':
                brac[j] = tmpbrac.pop()

    # かっこの中身と乗除算
    while i < len(exp):
        # かっこの中身は再帰的に計算
        if exp[i] == '(':
            num.append(calc(exp[i + 1:brac[i]],brac))
            i = brac[i]
            if ope:
                r = num.pop()
                l = num.pop()
                num.append(eva(l, r, ope))
                ope = ""
        elif exp[i] in ["*", "/"]:
            ope = exp[i]
        elif exp[i] in ["+", "-"]:
            ops.append(exp[i])
        elif exp[i] == "=":
            pass
        elif exp[i].isnumeric():
            temp = exp[i] # 数値 2桁以上にも対応させる
            i += 1
            while i < len(exp) and exp[i].isnumeric():
                temp += exp[i]
                i += 1
            i -= 1 # 最後の数字に戻る(最後にi+=1しているのでこれでいい)
            num.append(int(temp))
            if ope:
                r = num.pop()
                l = num.pop()
                num.append(eva(l, r, ope))
                ope = ""
        i += 1
    while len(ops) != 0:
        num.appendleft(eva(num.popleft(),num.popleft(),ops.popleft()))

    return num[0]


n = int(input())
for i in range(n):
    print(calc(input()))