Still not quite sure exactly what you want, but maybe this will give you some ideas.
import re numstring = '11111111113143111' numlist = [int(numstring[i]) for i in range(len(numstring))] total = sum(numlist) print(f"The sum of the numbers is {total}") if total % 8 == 0: print("We can make {sum(numlist)/8} groups with a sum total of 8 from the numbers.") def count8(alist): group = [] for i in range(len(alist)): group.append(alist[i]) if sum(group) > 8: del group[-1] elif sum(group) == 8: return group groups = [] while not sum(numlist) <= 8: mygroup = count8(numlist) print(mygroup) groups.append(mygroup) for m in mygroup: numstring2 = re.sub(str(m), 'X', numstring, count=1) numstring = numstring2 numstring = numstring.replace('X', '') numlist = [int(numstring[i]) for i in range(len(numstring))] groups.append(numlist)
buran write Nov-24-2023, 07:43 AM:
Please, don't provide answers to homework questions without effort from OP
Please, don't provide answers to homework questions without effort from OP