본문 바로가기
코딩 공부방 👩‍💻👨‍💻/알고리즘

[Python] 해커랭크(HackerRank) : Loops

by ByJinnie 2023. 2. 16.
반응형

[문제] 

STDIN과 반복문을 연습하는 문제입니다. 정수 n이 입력되면, 0부터 순차적으로 n개의 정수가 num[]에 담깁니다.

이후 num[]에 담긴 숫자들의 제곱값이 순차적으로 출력돼야 합니다.  

 

예시)

입력값 :

5

 

출력값:

0

1

4

9

16

 

[코드]

if __name__ == '__main__':
    n = int(input())
    
    num = []
    
    for i in range (n):
        num.append(i)
    
    for i in range (n):
        print(pow(i, 2))

 

* 문제 출처 (Prepare > Python > Introduction > Loops)

: https://www.hackerrank.com/

 

HackerRank

HackerRank is the market-leading technical assessment and remote interview solution for hiring developers. Learn how to hire technical talent from anywhere!

www.hackerrank.com

 

반응형

댓글