what is a function Now that we’re starting to get used to functions…we need to start to understand how to design them ourselves. First we’ll review some topics from Wednesday and then re-motivate why functions are useful - to encapsulate code. Then, we’ll start to understand all of the details of defining our own functions, from names, to parameters, to awesome functionality.

Functions allow us to tackle the key CS concept of abstraction. Programming is like making an investment in your future – we do a bunch of work now in order to be lazy later. Why? Think of it this way. Programming is basically like considering all of the tasks you do each day, and making a cool machine (aka a function) in order to automate that task. But what happens when you have two very similar tasks. For instance, what if on Mondays you have an Ego Waffle…but on Tuesdays you have toast.

Toasting those things is a very similar process. Do you really need to build a SEPARATE machine to toast toast…vs toasting egos? Of course not! You can just make one machine that is able to do both of those actions. This is the concept of abstraction at play and is an incredibly powerful idea in computer science both when creating our own machines (functions) and teaching the computer new ways of representing the world around us (data types).


Today's Resources

1. Exercise Files

Download Exercise Files

2. Slides

3. Pre-Recorded Lecture Video(s), Mini-Quizzes, and Live Recordings

Available Videos
Link Title Type Duration
Video 1 Live Lecture Recording lecture 50:00

4. Supplemental Materials

  • Charles Severance - Ch 4: Functions – Python for Everybody (ReadingVideo)

5. Mini-Quiz 2: Variables, Operators, and Using Functions

If you did not participate in class or were unable to attend then you should use this Canvas Quiz as a substitute after watching the recorded lecture (posted after class).