CSE 1010 Lecture Notes - Lecture 8: Functional Decomposition
jadetortoise401 and 55 others unlocked
84
CSE 1010 Full Course Notes
Verified Note
84 documents
Document Summary
Say we are farmers with a farm that is 3 squares high, and 4 square wide. Two dimensional array is represented by lists within lists. >>> f = [ [0, 0], [0, 0], [0, 0] ] >>> f = [ [0 for i in range (ncols)] for j in range (nrows) ] To represent planting one seed in each square, we can do this by defining a collection of functions, starting with planting a single seed. def plantsquare(field, row, col): Creating a function that plants an entire row def plantrow(field, row) : ncols = len(field[row]) #using a function inside a functions plantsquare(field, row, cols) for col in range (ncols): A function that plant the entire field def plantfield(field): nrows = len(field) for i in range(nrows): plantrow(field, row) They use functional decomposition meaning functions call other functions. This makes the functions smaller and easier to read.