How to write a code in Python language according to the following instructions:
- Int values will be received from the user. When the user enters the value 0, the value retrieval process will be finished.
- The entered values will be stored in an array.
- Groups must have a minimum number of groups, with the sum of the elements of each group being less than 70
- Groups will be printed on the screen.
I wrote but it is not working. How can i solve the problem?
aray = []while True: a = int(input("Sayı gir:")) if a != 0: aray.append(a) else: breakx = 700aray.sort(reverse=True)aray2 = aray.copy()array =[]target = 700groups = []currentGroup = []currentSum = 0for number in fonk(x,aray,aray2): if currentSum + number <= target: currentGroup.append(number) currentSum += number else: groups.append(currentGroup) currentGroup = [number] currentSum = numbergroups.append(currentGroup)for group in groups: print("Group:") for num in group: print(num, end=" ") print()def fonk(x,arr, aray2): count = 1 min = 710 for in1 in range(len(arr)): i = arr[in1] flag = False jj = 0 for minfind in aray2: if minfind < min: min = minfind for j in aray2: if x >= j: flag = True jj = j aray2.remove(jj) break if not flag: continue if x >= jj: x -= jj array.append(jj) if x==0 or x<= min: x=700 count+=1 continue else: x = 700 count +=1 return array
Inputs:
40010700200600490160300200320
My Outputs:
Group:700Group:600Group:490 200Group:400 300Group:320 200 160Group:100
But the output should be:
700600 100490 200400 300320 200 160