generate functionWed, 22 Feb 2023

the total sum of integers entered on a new line must not exceed 'n'. if the sum of the input values exceeds 'n', output the word "Enough!, the last sum that does not exceed, and the number of values that do not exceed

def add(a, n): sum = 0 k = 0 for i in range(n): sum += a[i] if sum <= n: k += 1 return k, sum a = [] n = int(input()) for i in range(n): a.append(int(input())) k, sum = add(a, n) if sum > n: print("Enough!") else: print(sum) print(k)

Questions about programming?Chat with your personal AI assistant