Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #This program declares a function that accepts two list of numbers and returns the list with the greatest sum
- # Assume that the two lists must have different sum
- #function
- def greater_sum(list1, list2):
- if sum(list1) > sum(list2): #This syntax will print list1 if the sum of its elements is greater than list2
- print(list1)
- else:
- print(list2) #This syntax will print list2 if the sum of its elements is greater than list1
- greater_sum([1, 2, 3], [1, 2, 4])
- greater_sum([1], [ ]) #Example(The two arguments must be lists)
Advertisement
Add Comment
Please, Sign In to add comment