Generation

generate functionMon, 13 Mar 2023

Let Q,W,E,R,T,Y,,U,I,O,P,A,S,D,F are 14 members with points 1,2,3,4,5,5,4,3,2,1,2,3,4 respectively.Get combination of 7 members out of 14 members without repeating and sum of the combination should be less than or equal to 10 points

from itertools import combinations Q,W,E,R,T,Y,,U,I,O,P,A,S,D,F = 1,2,3,4,5,5,4,3,2,1,2,3,4 k = 7 l = [Q,W,E,R,T,Y,,U,I,O,P,A,S,D,F] comb = combinations(l, k) combinations = [] for i in list(comb): if sum(i)<=10: combinations.append(i) print(*combinations, sep="\n")

Questions about programming?Chat with your personal AI assistant