Advertisement
ralphdc09

its102.pr.wk.05.07.num01

Oct 22nd, 2021
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.48 KB | None | 0 0
  1. # define a function that sum all the numbers in a list
  2. # sum_list()
  3. def sum_list(number):
  4.     total = 0
  5.     for x in number:
  6.         total += x
  7.     return total
  8.  
  9.  
  10. # initialize a list that contains a number element
  11. num_list = (5, 4, 3, 2, 1)
  12. # print the list num_list
  13. print("The list of numbers is: ", num_list)
  14.  
  15. # call function sum_list() to get the sum of the numbers in list
  16. print("The sum is: ", sum_list(num_list))  # this will print the sum of the numbers in list num_list
  17.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement