GIS5103 Module 2: Python Fundamentals
Putting the "fun" in fundamentals -- it's Module 2: Python Fundamentals!
This week, we were given the rundown, a Python bootcamp, so to speak. We were taught everything from values and variables, lists, tuples, indexes, and loops (for and while) to Booleans and so on. Honestly, I often get stuck on the fundamentals when it comes to understanding and working with Python. I tend to get a fair grasp of it, but I find myself frozen trying to make things from a blank slate. Module 2, however, had a great balance between getting more comfortable working with an existing framework and making scripts from scratch. Overall, I feel like my foundational understanding of Python has been strengthened, and so has my confidence.
Module 2's lab was broken up into 4 parts. Part 1 covered lists and indexing. Part 2 covered troubleshooting and correcting 2 errors in a dice game randomizer. Part 3 required a loop to generate 20 random numbers between 0 to 10. And Part 4 required another loop that removed a designated "unlucky number" from the list in Part 3.
| Module 2 Lab - Part 1. We had to use our full name to then be used as a list, from which we retrieved our last name. |
| Module 2 Lab - Part 2. A dice randomizer game featuring a pre-set list of player names. |
On the other hand, Part 2 was less about scripting from scratch and more on error fixes in the pre-made script. This one was interesting because it introduces how useful Python is in identifying errors in the script for you. Also, a particular string needed fixing, which I pondered if using an f-string would be fair. Talking with my colleagues and also just testing the script, it would still function. It seems like depending on who your audience is, the f-string can help with script efficiency with the caveat that it may detract from readability depending on who reads it. I'll continue to play around and think about when would be good places to use f-strings.
| Module 2 Lab - Parts 3 & 4. The 20 number randomizer and unlucky number removal. |
Finally, we've reached the behemoth end with Parts 3 & 4. This one proved more complicated and took me a few iterations and runs to get it perfect, but it was a good challenge to wrap my head around loops again. Like in Part 1, this section was one we had to do from a blank slate. At first, I placed a break in my while loop during the removal process, but I realized it was messing up the loop and not removing all the unlucky numbers from my list. The break was unnecessary, and I could just use the while statement as is. Once the list contained no unlucky numbers, the script would end naturally.
| Success! The results of the complete Module 2 Script in IDLE Shell. |
As you can see, the script works as intended! I did add some extra print statements to break up each section for increased readability as well as other personal touches.
Comments
Post a Comment