Back to Browse

Using functions to reduce duplication: The pyramid example

125 views
Aug 30, 2020
26:27

An example of using functions to simplify a small Python program, taking from _Introduction to Computing and Programming in Python: A Multimedia Approach" by Guzdial and Ericson (4th. Ed). This starts with the `pyramid()` example (Program 13, p. 49), and * Make the lines more uniform so it's easier to see the pattern in the function definition * Extract a new function `pyramidLine()` that captures the relationship between the number of spaces and characters so we don't have to repeat that logic. * Use a for-loop to eliminate the repeated calls to `pyramidLine()`.

Download

1 formats

Video Formats

360pmp436.0 MB

Right-click 'Download' and select 'Save Link As' if the file opens in a new tab.

Using functions to reduce duplication: The pyramid example | NatokHD