Lab 5

  • Example of recursion: Using VPython to draw an H-tree. Source code.
  • In-Lab Problem: Write a recursive function that takes as one parameter – a list with nested lists containing integers. Sum up all the elements.
    • Hint: You will want to use the following syntax in your program.
      if type(L) == list:
    • Skeleton:
      def recsum(L):
          ##YOUR CODE HERE
    • Example input:
          >>> recsum([1,2,3])
          >>> recsum([1,2,[3,4,5]])
          >>> recsum([[1,[4,5]],-4,[[6,[7],[9,10]],0]])

Sample Solution

cs190c/lab5.txt · Last modified: 2008/04/18 11:40 by alint
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki