Week 5 Reflections
Functions and Strings
Due: 11:59 PM on Sunday, March 7
Weekly Recap
Congratulations! We have finished the fifth week of class. During this week, we continued studying the idea of functions, which allow us to split up our solution into smaller pieces (basically small mini-algorithms) that each accept their own inputs, do some work, then can produce an output. We also started to look more in-depth into how Python (and many other programming languages) understand text data through strings. To recap:
- On Monday, we looked at additional aspects of functions. We 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. To explore this idea (and creating multiple functions in the same program), we wrote a program that can draw multiple different shapes (rectangles, right triangles, and pyramids) out of stars based on user input. We also discussed how functions can take their own inputs (using parameters and arguments). In this way, functions are basically small mini-programs inside of our programs.
- On Wednesday, we discussed the return statement, which is how functions output data back to where the function was called (which can be saved using a varaible assignment in front of the function call). We discussed how functions that return information are like nouns -- the function call represents some information that can be saved to a variable or otherwise used in our programs -- whereas functions that do not return anything are like verbs -- they do work for us, but do not represent any particular information. We also did a class exercise developing a function to determine whether an inputted character was a vowel.
- On Friday, we also explored the differences between global and local variables in our programs. Then, we started exploring how Python represents text using strings, which are sequences of characters. Working with text is very important for interdisciplinary applications of computer science in the humanities, social sciences, and natural sciences. We discussed how we can index specific locations inside of a string, as well as create substrings of some given text. We did a class exercise creating a function that counts the number of hashtags used in a given social media post. We also looked at several functions available for working with strings.
- In lab, we worked on creating our largest program to date -- an image editing program that can apply filters (similar to Photoshop or Instagram) to an image of the user's choosing. Through this program, we gained practice creating our own functions (e.g., one per filter), as well as sentinel while loops for continually interacting with a user until they are ready to quit the program.
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 5 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.