본문 바로가기
백준 - 파이썬/단계별 - 3 (반복문)

[백준/파이썬] 10951번 A+B - 4 | input 예외처리

by miiinn 2025. 4. 30.

 

* 방법 2를 더 많이 사용

while True:
    try:
        A, B = map(int, input().split())
        print(A+B)
    
    except EOFError:
        break

 


 

import sys

for line in sys.stdin:
    A, B = map(int, line.split())
    print(A+B)

 

애초에 for line in sys.stdin이 sys.stdin의 전체 파일에서 한줄(line)씩 읽는 코드이므로

readline()을 하지 않아도 된다.