백준 10951번을 풀면서
https://www.acmicpc.net/problem/10951
while True:
a,b=map(int,input().split())
print(a+b)
위의 코드로 풀면 EOFError
가 뜬다.
인터넷을 찾아보니 수가 입력되지 않아서 에러가 발생하면 반복문을 끝낼 수 있도록 try - except 구문을 활용해야 한다고 한다.
while True:
try:
a,b=map(int,input().split())
print(a+b)
except:
break
위의 코드처럼 예외처리가 필요하다.
10952번.
a,b=1,1
while (a!=0 and b!=0):
a,b=map(int,input().split())
print(a+b)
a,b=1,1
while (a!=0 and b!=0):
a,b=map(int,input().split())
print(a+b)
이건 왜안될까....
while 1:
a,b=map(int,input().split())
if (a==0 and b==0):
break
else:
print(a+b)
이건 왜 맞을까....