# Program to add numbers # (user enters number of numbers, then numbers) # Matt Bishop, Apr. 24, 2009 # for ECS 10 Spring 2009 # add the numbers and print the sum # parameter: listnum, a list of numbers def addup(listnum): # initialize sum sum = 0; # add each number in list to sum for i in listnum: sum = sum + i; # print result print sum; # read a list of numbers and print the sum # calls: function addup def main(): # prompt for count of numbers to be entered n = input("How many numbers do you want to add? "); # initialize list variable numbers = []; # ask user for next number and # append each number to the list for i in range(n): prompt = "Enter number %d: " % (i + 1); numbers = numbers + [ input(prompt) ]; # print the sum print "The sum of your numbers is", addup(numbers); main();