Week 4 Reflections
Modules and Functions
Due: 11:59 PM on Sunday, February 28
Weekly Recap
Congratulations! We have finished the fourth week of class. During this week, we learned about ways to use modules in our programs so that we can make use of code written by other people. For example, we used the picture module to create drawings (e.g., of a house), we used the random module to create random numbers (e.g., for a number guessing game), and the math module for more complicated mathematical operations (e.g., the square root for calculating distance in a route planning example problem). Additionally, we discussed strategies for avoiding mistakes in our code while programming, as well as strategies for debugging to remove any mistakes. We also learned about exceptions, which occur when the flow of our program experiences something unexpected. Finally, we also started learning about how we can implement reusable algorithms for small parts of our problems using functions. As a recap:
- On Monday, we learned how to use modules in our programs so that we can make use of more elaborate functionality than what is built into the basic Python language. We talked about a real-world route planning example (similar to Google or Apple Maps) and how the computer can make use of different types of information to help benefit users. We look briefly at the math and random modules from Python. We also discussed how computers think about graphics (as collections of many dots called pixels that each store their color information as an amount of red, green, and blue).
- On Wednesday, we explored the use of the picture module that we will use to create graphics in this course, and we worked through an example of algorithmically drawing a house using simple shapes (e.g., rectangles, triangles, and circles). Afterwards, we moved to the topic of debugging and exceptions where we discussed strategies for both implementing our programs (e.g., working on small pieces at a time and testing that they are correct before moving on to the next small piece) and debugging our programs (e.g., using print statements to know when parts of the code are reached or the values of variables, taking a break to refresh our minds). Finally, we introduced different types of exceptions that occur when data in our program doesn't match expectations.
- On Friday, we introduced functions as a way of giving names to blocks of code in our programs so we can simply refer to those blocks by name rather than having to re-type or copy-and-paste them over and over in our programs. We also discussed how splitting our programs into functions is helpful in thinking about the different steps needed to solve our problems -- each function represents a small part of the solution that addresses a small part of the overall problem. We also discussed how programs can use a "main" function to control the narrative of our solution so that it is easier to understand what is happening in the program.
- In lab, we practiced creating our own art with the picture module. We also practiced graphics combined with for loops to draw a pyramid, as well as draw random darts hitting a dart board to estimate the value of π.
Your Reflections
In this activity, you have the opportunity to reflect on your own experiences and connections with computer science. In particular, you should answer the following three questions:
- What did you learn this week?
- What would you now like to know more about?
- What connections can you make between something from class this week and your life (e.g., your personal interests, your future goals, your other classes, or society at large)?
You should type up your answers to the above questions in a single document using your favorite word processing software (e.g., Microsoft Word, Apple Pages, Google Docs), save the file as a PDF, and upload it to Gradescope under the assignment "Week 4 Reflections". Each answer should be at least one paragraph of 3-5 sentences (instead of 3-5 sentences total across all answers).
At the end of your document, please indicate that you have followed the honor code on this assignment by writing:
I have adhered to the Honor Code in this assignment.