티스토리 뷰

Hackerrank/Python

List Comprehension

.   2022. 2. 5. 13:34

정수 x, y, z, n을 입력 받는다.

[0, x] 범위에 속한 정수를 i, [0,y] 범위에 속한 정수를 j, [0, z] 범위에 속한 정수를 k라 할 때,

i+j+k가 n과 다른 [i, j, k] 쌍을 출력한다.

if __name__ == '__main__':
    x = int(input())
    y = int(input())
    z = int(input())
    n = int(input())
    
    l = list()
    
    for i in range(x+1):
        for j in range(y+1):
            for k in range(z+1):
                if i + j + k != n:
                    l.append([i,j,k])
                    
    print(l)

 

List Comprehensions | HackerRank

 

List Comprehensions | HackerRank

You will learn about list comprehensions.

www.hackerrank.com

 

'Hackerrank > Python' 카테고리의 다른 글

Nested Lists  (0) 2022.02.06
Find the Runner-Up Score!  (0) 2022.02.05
Print Function  (0) 2022.02.05
Write a function  (0) 2022.02.05
Loops  (0) 2022.02.05
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/07   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31
글 보관함