Week 357 – June 29th to July 5th

Last week (Week 356) was the worst week I had studying Computer Science, yet somehow this week was even worse. 😣 I basically got nothing done on KA only making it through one lesson in total. The silver lining is that I did get some CS work done outside of KA and I did make some progress learning Python and getting better at coding, but the bottom line is that my effort was incredibly poor. Like I said last week, part of the issue is that what I’m learning now is more complicated than what I was learning at the start and I’m not finding it nearly as intuitive as I was initially. It’s like going from arithmetic where things seem obvious to algebra where you actually have to think through what you need to do to balance equations. (That was the case for me, anyways.) I have a million other excuses as to why I didn’t get more done, but IMO excuses are bullshit and the bottom line is I just didn’t try hard enough. So, all in all, I’m disappointed with myself this week but I’m hoping that my disappointment will fire me up to have a much more productive upcoming week to make up for this one.

Here are the few things I made notes on this week, starting with the Project from Unit 5:

Unit 5 – Automating Tasks with Lists

Lesson 5 – Encrypting Messages

Project: Ciphers

I was already ~80% of the way through this project when I got back to it at the start of the week. It took me ~15 minutes just to refamiliarize myself with the code which was annoying, but I asked Gemini if programmers usually do this — take a break from coding, get back to it, and then need to spend time remembering what was going on where they left off — and it said this was common which made me feel a bit better. Anyways, the purpose of this project was to take a message and encrypt it. Following Gemini’s instructions, I did this by swapping back-to-back characters in the message (i.e. c[1] with c[2], c[3] with c[4], etc.) and then shifting all the swapped characters ahead in the alphabet by 9 characters.

I REALLY struggled with the encryption part of this and essentially just had to copy what Gamini gave to me. (So, I basically cheated. 😒) But I still learned a bit about what was going on and how everything worked, so I have that going for me which is nice. After that, the steps for decryption were simple as I literally used the exact same code for decryption as I used for encryption with the only difference being that for the shift parameter, I put a (–) sign in front to move the characters back 9 characters in the alphabet.   

Unit 6 – Analyzing Data with Dictionaries

Lesson 1 – Dictionaries

Article – Datasets and Data Structures

This article talked about what are called “dictionaries” and how they work. The photo of my notes above was from the first example in the article. I copied out the code thinking it would help me memorize the syntax/notation. You can see that the dictionary itself is on lines 2–11. The words to the left of the colon are known as “keys” and the words to the right of the colon are known as “values”. You can look up a value from its key but you can’t look up a key from its value. The dash_index variable finds the index of the first “–” in a given phone number. The code variable takes the second character (to avoid the “+” in the phone number) to the character just before the first “–” and turns those numbers which are at that point a string into an integer. Then, if the area code is in the dictionary, the statement print(f”call from {calles_codes[code]}.”) looks up the area code (the key) and inputs the associated country (the value). This example is pretty simple but makes it pretty clear how/why dictionaries will be useful. I’m definitely going to need more practice writing out the syntax for dictionaries in order to memorize how to use them, but I don’t think it’ll take me that long to figure out. 

This was the second example from the article. In this example, the program stores the stats for a basketball player (Caitlin Clark) in a dictionary. It passes the dictionary as an argument to the function, relying on the descriptive keys to access the stats (i.e the values) it needs. I was a bit confused how, for example, field_goals = stats[“field_goals_attempts”] called the value 580 from the dictionary given that the parameter “field_goals_attempts” was a string. Suffice it to say I eventually figured it out. I think the square brackets are used to denote that the string is actually used as something like an index, but I’m not 100% sure. (In fact, what I just wrote may make no sense whatsoever. 🙃)

This example was/is a bit confusing to me but I think I understand how it works. It takes the sentence, puts it into the function count_words which starts with an empty dictionary, splits the words apart and lowercases them, then iterates through the list and adds the words to the empty dictionary as keys IF the word that’s being looked at isn’t already in there. It also sets the value associated with the word to 1. If the word is already in the dictionary, it increments the value associated with the word/key that’s being looked at by 1. It took me a minute to figure out that word_counts[word] will add the given word to the dictionary as a key if it’s not already in there.

Exercise – Trace Dictionary Keys

Question 1

Question 2

This exercise wasn’t too hard. I went 4/4 in less than 10 minutes. The only question I wasn’t sure about was Question 2 from above as I wasn’t sure if the second file_renames[…] would be added to the dictionary. I assumed it would be and was correct. 

Challenge: Login Portal

This challenge was tough but not the hardest one I’ve had to do. Still, I had to get Gemini’s help with Step 2 and Step 3. 👎🏼 In Step 2, I wasn’t sure how to check if the Username and Password were associated with each other and if both were in the “accounts” dictionary in users.py (which isn’t shown in the screenshots above). On line 13, I initially wrote “if username in counts: … ”, but I needed to write, “if username in accounts and accounts[username] == password.”

For Step 3, on line 27 I initially wrote “if username in accounts[username]: …” but should have written “while username in account: …” so I wasn’t too far off. Using “while” creates the loop that continually asks the user to enter a new username if they continuously enter a username that was already taken, and switching accounts[username] to accounts was necessary because accounts[username] would == the value of “username”. The syntax accounts[username] wouldn’t make sense because the username may or may not be in the dictionary, so it resulted in what’s called a Keyerror.

I technically finished the challenge but, as you can see in the third screenshot above, KA always gives a bonus task at the end once you complete the challenge which I want to do. I didn’t get to it this past week but am going to do it this coming week before I move on to the second Lesson of Unit 6.

And that was it for this week. 🫤 Like I said, it was pretty a pretty pitiful week and a fairly poor performance by me, overall. That said, I’m watching another series on Python Basics on YouTube and am still reading the book Automate the Boring Stuff with Python while working through the exercises from that book so if you take that into account, I still had a decent week overall, but certainly one that could have been better, nonetheless. I’m REALLY hoping I don’t come back next week to write my next post and have to say that for a third week in a row that I had a poor performance. So, more than usual, fingers crossed I can be productive this week and make some decent progress so I can get things back on track and start getting some momentum again! 🤞🏼😩

Leave a Reply

Your email address will not be published. Required fields are marked *