12.07.2015 Views

Think Python - Denison University

Think Python - Denison University

Think Python - Denison University

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

60 Chapter 6. Fruitful functionsspaceisastringofspacecharactersthatcontrolstheindentationoftheoutput. Hereistheresultoffactorial(5):factorial 5factorial 4factorial 3factorial 2factorial 1factorial 0returning 1returning 1returning 2returning 6returning 24returning 120If you are confused about the flow of execution, this kind of output can be helpful. It takes sometimetodevelop effective scaffolding, but alittlebit of scaffolding can save alot of debugging.6.10 Glossarytemporary variable: A variable usedtostorean intermediate value inacomplex calculation.dead code: Part of a program that can never be executed, often because it appears after a returnstatement.None: A special value returned by functions that have no return statement or a return statementwithout an argument.incremental development: A program development plan intended to avoid debugging by addingand testingonlyasmallamount of code at atime.scaffolding: Code that isused during program development but isnot part of thefinal version.guardian: A programming pattern that uses a conditional statement to check for and handle circumstancesthat might cause an error.6.11 ExercisesExercise 6.4 Draw astackdiagram forthe following program. What does theprogram print?def b(z):prod = a(z, z)print z, prodreturn proddef a(x, y):x = x + 1return x * ydef c(x, y, z):

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!