[Python] 백준알고리즘 2741

단계별로 풀어보기-for문

Posted by Mel on 2019-12-21

문제

N찍기
자연수 N이 주어졌을 때, 1부터 N까지 한 줄에 하나씩 출력하는 프로그램을 작성하시오.


입력

첫째 줄에 100,000보다 작거나 같은 자연수 N이 주어진다.


출력

첫째 줄부터 N번째 줄 까지 차례대로 출력한다.


예제 입력1

5


예제 출력1

1
2
3
4
5


풀이

1
2
3
4
N = int(input().strip())

for i in range(1, N+1):
print(i, sep = '\n') # sep = '\n' 줄바꾸기
1
2
3
4
5
6
7
# sys.stdin.readline() 활용

import sys
N = int(sys.stdin.readline().rstrip())

for i in range(1, N+1):
print(i, sep = '\n')

출처

백준 알고리즘