oper = input("输入运算符号(目前只支持+/-)")
if (oper == "+"):
maxlen = [input(),input()]
a, b = map(int, maxlen)
r = a + b
maxlen.append(str(r))
maxlen = max(len(s) for s in maxlen)
print(f'{a:>{maxlen+4}d}')
print(f'{"+":>3s}{b:>{maxlen+1}d}')
print(f'{"-"*(maxlen+4):>{maxlen+5}s}')
print(f'{r:>{maxlen+4}d}')
elif oper == "-":
maxlen = [input(), input()]
a, b = map(int, maxlen)
r = a - b
maxlen.append(str(r))
maxlen = max(len(s) for s in maxlen)
print(f'{a:>{maxlen+4}d}')
print(f'{"-":>3s}{b:>{maxlen+1}d}')
print(f'{"-"*(maxlen+4):>{maxlen+5}s}')
print(f'{r:>{maxlen+4}d}')
感谢【micthis】提供的帮助