Python/BaekJoon

[Baekjoon] 1000. A+B

kyra 2022. 7. 30. 08:45
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) 문자열을 정수형으로 바꾸어 더한 뒤 출력한다.