import sys idx = 0 for line in sys.stdin: a = line.split() if idx == 0: line_num = int(a[0]) else: print(int(a[0]) + int(a[1])) idx += 1 用idx记录读到的行数,并条件判断执行即可