Print Function
if __name__ == '__main__':
n = int(input())
for i in range(1, n+1):
print(i, end="")
해설
range함수와 print함수의 파라미터(end)설정을 통한 프로그래밍이다.
range
https://bohemihan.tistory.com/entry/HackerRank-Python-Solution-Loops
https://bohemihan.tistory.com/entry/HackerRank-Python-Solution-Hello-World?category=986077
# print(value(s), sep= ‘ ‘, end = ‘\n’)
# print함수의 파라미터 end의 기본값은 '줄바꿈(‘\n’)'이다 (end를 설정하지 않는 경우)
>>> n = 3
>>> for i in range(1, n+1):
... print(i)
1
2
3
>>> n = 3
>>> for i in range(1, n+1):
... print(i, end='\n')
1
2
3
# print함수의 파라미터 end를 공백("")으로 설정하는 경우
>>> n = 3
>>> for i in range(1, n+1):
... print(i, end="")
123
'Develop > hackerrank.com' 카테고리의 다른 글
HackerRank Python Solution / Find the Runner-Up Score! (0) | 2022.01.01 |
---|---|
HackerRank Python Solution / List Comprehensions (0) | 2022.01.01 |
HackerRank Python Solution / Write a function (0) | 2021.12.31 |
HackerRank Python Solution / Loops (0) | 2021.12.30 |
HackerRank Python Solution / Division (0) | 2021.11.12 |