In Class: Week 10, recursion
Create a week10 subdirectory
in your cs21/class directory and copy over my starting point files:
$ cd cs21/class
$ mkdir week10
$ cd week10
$ cp ~newhall/public/cs21/week10/* .
- Open recursion.py. We are going to write some iterative and
recursive versions of the same function. Iterative versions use
loops, recursive versions do not use loops, and instead contain
calls to themselves. The idea of recursive functions is based on
recursive definitions. For example, n! can be defined
- Lets try writing recursive factorial together
- Next, try writing an iterative version (using a loop) of sumInts
that takes a positive int value, n, and returns the sum of the
first n integers.
- Next, try writing a recursive version of the sum of n ints
- Open list_recursion.py. We are going to write some iterative and
and recursive functions that operate on lists.