Week 3 Reflections
Looping
Due: 11:59 PM on Sunday, February 21
Weekly Recap
Congratulations! We have finished the third week of class. During this week, we learned about different ways to tell a computer how to make a decision so that it does one thing in one situation, and something different in a different situation. We also further practiced our programming skills so that we can write solutions to problems that require the computer to repeat some activity. As a recap:
- On Monday, we continued learning about for loops. In particular, we explored different uses of Python's range keyword for creating sequences of numbers. We noted that by default, range counts up by 1 from 0 to the number before whatever number is given, but we can change both the starting number and how much the sequence increases (or decreases by). Starting a sequence with 0 might not seem natural to us, but the reason for doing so will make more sense later. We also created a countdown timer using a for loop, and as a class we designed and implemented a for loop that adds up the first n numbers.
- On Wednesday, we discussed how to trace what is happening in a for loop by hand-writing a table: the rows represent the different iterations of the loop, and the columns keep track of how the values of variables change inside the loop. Next, we explored the idea of nested loops where one or more for loops is part of the body of another for loop. For example, in a real-world hide-and-seek example, finding a given friend amongst a list of possible locations is an inner loop that would be repeated for every friend that we need to find. We looked at some examples of nested for loops in code, included creating a multiplication table, printing the days of the year, and drawing shapes using stars in Python.
- On Friday, we learned about while loops. While loops are similar to for loops in that they allow a computer to repeat steps, but while loops are unique in that they will continue looping as long as some condition is True (instead of looping for a predetermined number of times). We discussed how we can use while loops to improve our real-world decision making examples. For instance, in the example of a user logging into a website, we can use a while loop to keep prompting the user for passwords until they enter a correct one. Likewise, in the menu ordering example, a while loop allows the user to keep adding items to their shopping cart until they are ready to place their complete order. We also looked at two classic types of while loops. First, sentinel loops keep running until something important happens. Sentinel loops are often used to continue interacting with a user, for example continuing to ask a user for guesses in a number guessing game until they enter the correct guess, or offering a menu of actions the user can take until they decide to exit the program. Second, validation loops are used to help users understand that they need to enter certain types of inputs and keep prompting them until a valid value is inputted (e.g., numbers in a certain range, text in a certain format).
- In lab, we practiced using for loops (both singular and nested) to solve problems, such as writing lyrics for a song, calculating sequences, updating bank account balances, and creating simple images based on patterns.
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 3 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.