Identifier: PyRec
Prerequisites: TUR, LOOP, LIST, SiffListBuild
Transition from Sifflet to Python
Students should be able to:
Textbook Chapter 9, pages 305–310.
Recursive functions can be written in Python, or for that matter, most other programming languages, as well as Sifflet.
Study one or more of the Sifflet examples fact, sumFromZero. Define equivalent Python functions; i.e., translate the definitions into Python.
Python does not have built-in equivalents of the Sifflet list functions :, null, head, tail; therefore, we must define them.
Exception is an error (or sometimes just an abnormal condition); the raise statement allows the Python programmer to signal errors.Study one or more of the Sifflet examples length and sum (of a list). Translate their definitions into Python.
To trace a function means to show how it computes its result; in the case of a recursive function, this involves showing the actual parameters and return values for each call of the function.
Trace the Python versions of one of the functions from Practice 1 and one of the functions from Practice 2.