Python 알고리즘 - A+B-4

Code_Alpacat·2022년 1월 8일
0

Python 알고리즘

목록 보기
9/15

A+B-4

  • 이번 문제는 A+B-5와는 다르게 무한하게 반복되어 에러가 발생하면 멈추도록 try except를 사용해줘야한다. 에러가 발생하면 try except문을 먼저 적용해보는 것을 기억하기위해 작성한다.
while True:
    try:
        A, B = map(int, input().split())
        print(A+B)
    except:
        break

아니면 아예 try문 안에 넣어줘도 된다.

try:
    while True:
        A, B = map(int, input().split())
        print(A+B)
except:
    print("멈춰!")
profile
In the future, I'm never gonna regret, cuz I've been trying my best for every single moment.

0개의 댓글