Week 355 – June 15th to June 21st

I once again didn’t get through as much material on KA this week as I was hoping to, but nonetheless, I did learn a lot and spent quite a bit of time studying. Between KA, the books I’m reading (that include other exercises which I’ve been doing on VS Code), the CS50 videos, and other videos I’ve been watching about CS, I’m guessing I probably spent somewhere between 20–30 hours this week studying. I didn’t make it through Unit 5 on KA, unfortunately, only making it through (essentially) three out of the four lessons. Similarly to math, now that I’m getting further into this course, the concepts that are being taught in each unit are getting harder for me to understand. I can tell that I’m getting better at reading and understanding code though, so I’ve got that going for me which is nice, but it’s hard to wrap my head around the new concepts being taught while still trying to understand what I previously learned. It’s like trying to learn trig while only feeling 70% comfortable with algebra. But even still, I’m happy with how this week went overall, although I wish I could have gotten through Unit 5.

As I said, I made it through close to three Lessons in Unit 5. Here’s everything I made notes on this week:

Unit 5 – Automating Tasks with Lists

Lesson 1 – List Indices

Video – Tracing Lists

In this video, Kim explained how the computer stores lists in its memory and how it retrieves data. The most enlightening part of this video was her explanation of the fact that the computer stores each element in the list in its own place in memory and the addresses in a contiguous chunk of memory. Then it assigns pointers from each element’s address to each element. You can see this in the screenshot above. You can also see how in the screenshot there’s a variable called “Sample” that points to the datum 0.4 just like the final pointer in the “wave” list does. Having learned a little bit about pointers in CS50, this helped me understand why (or at least part of why) they’d be useful.

Exercise: Trace List Indices

Question 1

Question 2

This exercise helped me understand the syntax of lists. The syntax feels pretty intuitive to me so this exercise was pretty easy. I went 4/4 on the questions finishing them in < 2 mins.

Challenge: DNA Mutation

I unfortunately cheated a lot on this challenge. 😔 The main reason was because I had no idea what the instructions were asking me to do, but even if I did understand, I doubt I would have been able to figure out how to code Step 1 properly. I asked CGPT and it gave me the wrong solution. but “luckily” I realized that the solutions to all the challenges and projects are in Unit 8, Teacher Resources, so I looked at how Kim (or whoever) coded it and figured out the correct way to code Step 1. Even after I got through the challenge, which took me ~30 mins, it took me another 10–15 minutes looking at the screenshots to understand what was going on with the code and how it worked. Also, it was only halfway through the challenge that I realized what the instructions were asking me to do: to randomly change the sequence of “Guo”, “Cyt”, etc. by 1–3 elements.  SO CONFUSING! I would have learned more about lists and quicker if they’d just told me “switch these variables in a list, etc.” instead of “The DNA is bla bla bla. Switch the DNA…” It makes me think of Algebra 1 where all you really have to do is some basic equation but they package it in an elaborate, confusing story. Just tell me what to do and I’ll do it!  😡

Lesson 2 – List Iteration

Video – List Iteration

In this video, Kim talked about using loops to go through elements of a list. She said that programmers typically use “for loops”. She also explains how you can use the loop by going through the list’s index (i.e. for i in range(len(list))), or you can use what’s called a “for each” loop which just goes through every element in the list in chronological order. The former is called ‘iterating by index’ and the latter is called ‘iterating by element’. I believe iterating by element lets you copy and paste the data from a list to create a new list and iterating by index allows you to actually change the elements in the OG list (and also maybe and copy and paste the data, but I’m not sure).

Exercise: Iterate Over Sequences

Question 3

Question 4

This exercise was pretty easy but it definitely helped give me a better idea of how/when to use for loops by index and when to use them by element (if that’s the right way to say it). You can see that the first question uses a “for each” loop and the second question uses a “for… i in range of” loop. (I’m sure that’s the name for it, but I don’t actually know what it’s called. When iterating by index, it might just be called a straight-up “for” loop.)

Article – List Iteration Patterns

The point of this article was to help me better understand lists and how they work, but this little exercise that came up in the exercise was super helpful (although frustrating) for me to better understand Python/coding “logic” and how variables flow through each other. Looking at the second screenshot, it took me awhile to realize the program sort of “starts” from the bottom. Because direction = “”, this means direction = False. Since the while loop is not False (i.e. it’s True), it runs repeatedly. If the user inputs N/E/S/W, the character gets put into the function is_valid_direction which returns True. The while loop then turns to while not True (i.e. while False) which then stops the loop. If the user inputs anything other than N/E/S/W then the function returns False and the while loop stays while not False (i.e. True) and repeats. ALSO, it’s worth mentioning that this exercise explains that return direction == “N” or return direction == “E”, etc. can be rewritten as return direction in [“N”, “E”, “S”, “W”].

This program was in the same article as the one just above and, once again, I spent WAY more time trying to figure out how the program worked than trying to understand what I was supposed to change it. First of all, I stupidly didn’t grasp what the program was doing which was inserting “Golden Pumpkin” (lol) into the empty space, “”, in the list. Gemini made it clear that the for loop was going through each index and checking if the empty string was in it. If not, it kept checking each index until it found “”. When it found “”, it returned the index number as the variable slot which then using inventory[slot] = “Golden Pumpkin” would insert “Golden Pumpkin” into the list. 😮‍💨 (The actual point of this exercise was to use what’s called a “sentinel value” as a way to not return an error in the terminal if there were no empty strings.)

Challenge: Heart Rates

This challenge was pretty hard but what made it tougher was that I stupidly stopped and restarted it a few times which meant that each time I restarted, it took me five minutes just to remember what was going on. (The lesson being to always try and finish coding whatever I’m working on before stopping.) That said, I did manage to make it through Steps 1 and 2 on my own, but it was hard and I didn’t know what I was doing most of the time. I struggled thinking through how to properly implement list notation inside of for loops. But I think struggling through it helped me memorize the notation. For example, heart_rates[i] means the element’s value at i, so if the heart rate of the fifth element was 50, then heart_rate[5] = 50. I did get CGPT’s help with Step 3, BUT I was very close to getting through it on my own. I also asked CGPT to check my code after each step for feedback on how to improve it which I found quite helpful.

Lesson 3 – String Manipulation

Article – Strings as Sequences

This article talked about how strings are considered a sequence of characters which you can access through each character’s index. You simply use the same indexing techniques/methods used on lists. The screenshot shows all the examples that were shown in the article, I just copy and pasted the into a single IDE. The only example that was new to me was what’s called “string containment” which was shown in the example:

  1. if “go” in message:
  2.       print(“Found the substring.”)

I don’t have much to say about this other than it seems like it could end up being pretty useful.

Article – String Method Patterns

This article talks about what are called “string methods”. The first screenshot shows all the different string method examples that were given in the article. The first example talked about how you can use string methods to convert the character’s in a string to upper and/or lower case — not the OG string but a copy of it — and also remove specific characters at the start and end of a string with .strip(). The second example talked about how specific characters in a string can be counted using the .count() method and how you can use the .index() method to return the index of the first occurrence of a specific character in a string. The example I found interesting/helpful was:

  1. domain_start = email.index(“@”)
  2. return email [domain_start + 1:]

The final example talked about how you can split a string into a list of strings at specific characters with .split() which can be helpful for CSV files by using .split(“,”). You can then join separated strings together with .join(). At the end of the article, it gave a list of the most common methods used which you can see in the screenshots above.

Exercise: Evaluating String Expressions

Question 5

Question 6

This exercise was pretty easy but it still helped me get better at understanding how some of the string methods work. It wasn’t hard but I did fail it twice not understanding the methods precisely.

Article – String Formatting

This article was pretty interesting and informative. It was interesting to see that you can print variables by simply writing print(“example”, variable) . (This makes me wonder why you would need print(“example” + str(variable)) in the first place. 🤔) I’ve seen the other way of doing it before in CS50 — which is using an f-string: print(f“example {variable}”)) — so it’s nice to see it being brought up/used here on KA. It was also interesting to read the part about “\” being the Escape sequence key. I practiced using it by rewriting Kim’s examples in the first screenshot above in VS Code.

And that was it for this week. (Well, actually I did make it through the first two steps of the challenge of Lesson 3, but I didn’t finish it off so I figured I’d just wait until next week to talk about it.) So, as you can see, even though I didn’t finish Unit 5, I still got quite a bit of work done and learned a lot. I’m struggling to remember everything and understand how it all comes together in code, but overall I feel like I’m starting to get better handle on Python. I’ve realized that I’m going to need to spend a LOT more time actually coding little programs/exercises to memorize how to write Python code properly. It makes me think back to when I was first learning things in math like long division and I had to write out equations over and over to actually memorize the process of how it works. This is much harder than just watching videos explaining what a given concept is, but it’s what makes the biggest difference in actually learning how to apply what’s being taught. So just like learning math, I know that I’ll eventually be able to figure it out, I’m just going to need to keep doing it over and over until it sticks. (And I’m sure it will be super frustrating. 🤷🏻‍♂️)

But as always, fingers crossed I can have a productive upcoming week so I can make some decent progress understanding all of this stuff and feel like I’m actually making progress becoming a programmer. 🤞🏼🤓