Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # define a function that sum all the numbers in a list
- # sum_list()
- def sum_list(number):
- total = 0
- for x in number:
- total += x
- return total
- # initialize a list that contains a number element
- num_list = (5, 4, 3, 2, 1)
- # print the list num_list
- print("The list of numbers is: ", num_list)
- # call function sum_list() to get the sum of the numbers in list
- print("The sum is: ", sum_list(num_list)) # this will print the sum of the numbers in list num_list
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement