Blessing988

Untitled

Feb 29th, 2020
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.63 KB | None | 0 0
  1. #This program declares a function that accepts two list of numbers and returns the list with the greatest sum
  2.  
  3. # Assume that the two lists must have different sum
  4.  
  5. #function
  6.  
  7. def greater_sum(list1, list2):
  8.  
  9.     if sum(list1) > sum(list2):         #This syntax will print list1 if the sum of its elements is greater than list2
  10.         print(list1)
  11.  
  12.     else:
  13.         print(list2)                    #This syntax will print list2 if the sum of its elements is greater than list1
  14.  
  15.  
  16.  
  17.                    
  18.  
  19.  
  20. greater_sum([1, 2, 3], [1, 2, 4])          
  21.  
  22. greater_sum([1], [ ])                  #Example(The two arguments must be lists)
Advertisement
Add Comment
Please, Sign In to add comment