Sort by

recency

|

1718 Discussions

|

  • + 0 comments

    import itertools if name == 'main': x = int(input()) y = int(input()) z = int(input()) n = int(input()) ls = [] ls1 = [] ls2 = [] for i in range (x + 1) : ls .append (i) for i in range (y + 1) : ls1 .append (i) for i in range (z + 1) : ls2 .append (i) result = list(itertools.product(ls , ls1 , ls2)) filtered_result = [list(x) for x in result if sum(x[i] for i in range (len(x))) != n] print(filtered_result)

  • + 0 comments

    Easy solution for the comprehesion list is

    if name == 'main': x = int(input()) y = int(input()) z = int(input()) n = int(input()) result = [] for i in range(0,x+1): for j in range(0,y+1): for k in range(0,z+1): if i+j+k != n: result.append([i,j,k]) print(result)

  • + 0 comments

    For me it was harder than an easy challenge but it helped me understand the comprehension list by first coding in for loop:

    result = []
    for a in range(0, x+1):
        for b in range(0, y+1):
            for c in range(0, z+1):
                if a + b + c != n:
                    result.append([a, b, c])
    
  • + 1 comment
    if __name__ == '__main__':
        x = int(input())
        y = int(input())
        z = int(input())
        n = int(input())
        b = [[i,j,k] for i in range(x+1) for j in range(y+1) for k in range(z+1) if i+j+k !=n]
        print(b)
    
  • + 0 comments
    if __name__ == '__main__':
        x = int(input())
        y = int(input())
        z = int(input())
        n = int(input())
        
    
        
        list_Com = [[i,j,k] for i in range(x+1) for j in range(y+1) for k in range(z+1) if i+j+k!=n]
        
        
        print(list_Com)