Try, Except
input()
은 파일의 끝일 때 EOFError를 발생시킴 -> except로 처리가능readlines()
사용sys.stdin.readlines()
을 이용하면 파일의 끝까지 가져올 수 있음 -> for문으로 반복while True: #for문은 많이 썼으니까 while로 한번 처리해봄!
try:
a,b = map(int, input().split())
print(a+b)
except:
break
sys.stdin.readline()
을 쓰고 있다.백준's Tip
맨 끝의 개행문자까지 같이 입력받기 때문에 문자열을 저장하고 싶을 경우.rstrip()
을 추가로 해 주는 것이 좋다.
import sys
lines = sys.stdin.readlines() # 파일 전체 입력
for line in lines:
a, b = map(int, line.split()) # line 한줄씩 받아서 a,b로 분배
print(a+b)