This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: Engineering Computation: Tutorial 11 Problem Solving with Computing, using the Python Language What’s in your toolbox? Print statement, string literals Basic calculator, integer division Variables Builtin functions Math library functions Straightline programs Branching programs Python lists For loops Nested for loops Strings While loops Converting between number system using Python Matplotlib Program Design File Processing Graphics Functions Scope of Variables Comments Complex Conditions Testing and Debugging Exception Handling Common Loop Patterns Boolean Operators Unit Testing Classes and Objects Data Collections Searching and Sorting 2 Today’s Topics: 1 Recursion 3 Recall: Functions can call other functions. Let f 1 be the function that maps an integer n to the integer f 1 ( n ) = n 2 Let f 2 be the function that maps an integer n to the integer f 2 ( n ) = n X i =0 f 1 ( i ) = f 1 (0) + ··· + f 1 ( n ) if n ≥ if n < f 1 implementation def fun1 (n ) : return n ** 2 *pyramid of golfballs f 2 implementation def fun2 (n ) : sum = 0 for i in range (n+1) sum += fun1 ( i ) return sum 4 Functions that call themselves.Functions that call themselves....
View
Full
Document
This note was uploaded on 10/14/2011 for the course ENGINEER CHEM ENG 3 taught by Professor Ghosh during the Spring '11 term at McMaster University.
 Spring '11
 Ghosh

Click to edit the document details