Q. Given two integers A and B, calculate their sum.
<Input>
The first line contains two integers A and B. (0 < A, B < 10)
<Output>
Output one line of one integer, A+B.
A, B = input().split()
print(int(A)+int(B))
1) input(). split()을 사용하면 input으로 받은 값을 문자열로 바꾸고, 그 문자열을 split안에 있는 요소(여기서는 ' ')를 기준으로 나누어준다.
2) 각각의 나누어진 문자열이 A, B에 들어간다.
3) 문자열을 정수형으로 바꾸어 더한 뒤 출력한다.
'Python > BaekJoon' 카테고리의 다른 글
[코딩테스트 with 파이썬] 알고리즘 (1) - ArrayList와 LinkedList (1) | 2023.11.26 |
---|---|
[Baekjoon] Baekjoon 작성 시 팁, 주의사항, 자주 틀리는 것 (1) | 2022.10.05 |
[Baekjoon] 다시 풀어볼 문제들 (0) | 2022.10.05 |