I’m having trouble performing addition with two seperate lists. I can’t decide if I should be doing a nested list or not. I believe my logic is there. Find sum of list 1, find some of list 2, compare values, return bigger list.
Create a function named
larger_sum()that takes two lists of numbers as parameters named
lst2. The function should return the list whose elements sum to the greater number. If the sum of the elements of each list are equal, return
Here is my code:
#Write your function here def larger_sum(lst1, lst2): sum1 = 0 sum2 = 0 for i in lst1: sum1 = sum1 + i return sum1 for x in lst2: sum2 = sum2 + x return sum2 if sum1 > sum2: return lst1 else: return lst2 #Uncomment the line below when your function is done print(larger_sum([1, 9, 5], [2, 3, 7]))