Change Contents of the Bubble
Welcome to CS1315. Click on the python to add comments.

Looking for the book? They have it at the Engineer's Bookstore at 748 Marietta St NW. Here is there website: http://www.engrbookstore.com/ - Monica

Hotspots: Slides and CodeTA CornerComments?AnnouncementsFAQStatic Webspace
View this PageEdit this PageUploads to this PageHistory of this PageHomeRecent ChangesSearchHelp Guide

functions that sum the elements in a list of numbers

def sumListIterative(listOfNumbers):
  total = 0
  for num in listOfNumbers:
    total += num
  return total


def sumListRecursive(listOfNumbers):

  # Base case(s)
  if len(listOfNumbers) == 0:
    return 0
  elif len(listOfNumbers) == 1:
    return listOfNumbers[0]

  # Recursive definition
  else:
    return listOfNumbers[0] + sumListRecursive(listOfNumbers[1:])




Link to this Page