-
37 - 백준 온라인 저지에서 여러 줄 입력 받기 - 추가문풀 필요study with Q - 파이썬 2024. 4. 22. 20:19
#여러 줄 입력 받기 위해서는
- 한 줄 입력 : input() 함수 하나
input()
- 두 줄 입력 : input() 함수 두 개 사용
input() input()
- 여러 줄 입력 : 반복문 사용
N = 10 for n in range(N): input()
# 예시
문제
두 정수 A와 B를 입력받은 다음, A+B를 출력하는 프로그램을 작성하시오.
입력첫째 줄에 테스트 케이스의 개수 T가 주어진다.
각 테스트 케이스는 한 줄로 이루어져 있으며, 각 줄에 A와 B가 주어진다. (0 < A, B < 10)
출력 : 각 테스트 케이스마다 A+B를 출력한다.#테스트 케이스의 개수 T를 변수로 잡고 input 함수로 읽고, int 함수를 이용해서 정수로 변환한다. T = int(input()) #반복문을 이용해서 T를 반복해서 받고 #a에 숫자 두 개를 받고 split 함수를 이용해 공백을 기준으로 나눈다 #a의 0-index와 1-index를 잘라서 더하는 함수를 넣으면 for n in range(T): a = input().split() a_0 = int(a[0]) a_1 = int(a[1]) print(a_0+a_1) >>> 5 1 1 >>> 2 2 3 >>> 5 3 4 >>> 7 9 8 >>> 17 5 2 >>> 7
백준 온라인 저지 > 12, 13 제외한 반복문 문제 풀기
replit
'study with Q - 파이썬' 카테고리의 다른 글
39 - while 반복문 (0) 2024.04.25 38 - reversed() 함수와 별 피라미드 - 추가연습 필요 (0) 2024.04.22 36 - 수열의 일반항과 점화식, 등차 수열, 피보나치 수열 - 추가 문제 풀기 (0) 2024.04.16 35 - 범위와 반복문 (0) 2024.04.15 34 - 딕셔너리 확인문제 (0) 2024.04.10