样例过了但是全wa,Python,这是为啥
查看原帖
样例过了但是全wa,Python,这是为啥
1310541
_yjhhh楼主2024/3/15 19:17

hang = int(input())
li = []
li_c = []
for i in range(hang):
    p = input()
    li_c = p.split(' ')
    li.append(li_c)

for l in li:
    if l[0] == 'a':
        a = int(l[1]) + int(l[2])
        s1 = f'{l[1]}+{l[2]}={a}'
        print(f'{s1}\n{len(s1)}')
    elif l[0] == 'b':
        b = int(l[1]) - int(l[2])
        s2 = f'{l[1]}-{l[2]}={b}'
        print(f'{s2}\n{len(s2)}')
    elif l[0] == 'c':
        c = int(l[1]) * int(l[2])
        s3 = f'{l[1]}*{l[2]}={c}'
        print(f'{s3}\n{len(s3)}')
    else:
        num = li.index(l)
        l_c = li[:num:]
        l_c1 = l_c[::-1]
        for fnd in l_c1:
            if fnd[0] == 'a':
                d = int(l[0]) + int(l[1])
                str4 = f'{l[0]}+{l[1]}={d}'
                print(f'{str4}\n{len(str4)}')
                break
            if fnd[0] == 'b':
                e = int(l[0]) - int(l[1])
                str5 = f'{l[0]}-{l[1]}={e}'
                print(f'{str5}\n{len(str5)}')
                break
            if fnd[0] == 'c':
                f = int(l[0]) * int(l[1])
                str6 = f'{l[0]}*{l[1]}={f}'
                print(f'{str6}\n{len(str6)}')
                break
2024/3/15 19:17
加载中...