samedi 6 février 2021

while-loop could not be stopped (probably, additional problems that I have not recognize may occur)

I try to find an array (front_design_array) having been built by adding the elements of (array) to (f_ext_ele_groups). When the sum of any element in (f_ext_ele_groups) equals to 10, it is appended to (front_design_array). The sum of an element in (front_design_array) should not be bigger then 10. If an element bigger then 10, it is not added to (draft) list which is built for next iteration by assigned to (f_ext_ele_groups). But some mistakes that I couldnt recognize occured. While-loop does not end.

array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
f_ext_ele_groups= [[1], [2], [3], [4], [5], [6], [7], [8], [9], [10]]
                          
front_design_array=[]          
length=len(f_ext_ele_groups)    
while length > 0:               
    
    for var in f_ext_ele_groups:
        
        sumation = sum(var)
        
        if sumation ==10:
            front_design_array.append(var)
    
        elif sumation < 10:
            draft= []
            for ele in array:
                if int(var[0]+ ele) <= 10:
                    draft.append([var[0], ele])
                else:
                    continue

    f_ext_ele_groups=draft
    length=len(f_ext_ele_groups)

Aucun commentaire:

Enregistrer un commentaire