(py)为什么全WA诶?

P1957 口算练习题

Iicosia @ 2023-08-04 20:25:04

I = int(input())
op = "0"
strings = []
for i in range(I):
    strings.append(input())
for i in range(I):
    arr_s = strings[i].split(" ")
    if len(arr_s) == 3:
        s1 = arr_s[1]
        s2 = arr_s[2]
        if arr_s[0] == "a":
            op = "+"
        elif arr_s[0] == "b":
            op = "-"
        elif arr_s[0] == "c":
            op = "*"
        ans = str(eval(s1 + op + s2))
        S = s1 + op + s2 + "=" + ans
        Len = len(S)
        print(S)
        print(Len)
    if len(arr_s) == 2:
        s1 = arr_s[0]
        s2 = arr_s[1]
        ans = str(eval(s1 + op + s2))
        S = s1 + op + s2 + "=" + ans
        Len = len(S)
        print(S)
        print(Len)

|