This week's module continues examining Python fundamentals. Lists, methods, modules, and conditional statements were combined to produce a program with several outputs. This first portion of code was provided but there were two syntax errors that had to be corrected for it to run properly. The next portion of code had to be written from scratch. It needed to produce a
list of 20 randomly selected numbers between 0 and 10. To accomplish this I used a
while loop to
populate an empty list with 20 numbers (generated using the random module). The final portion of code had to eliminate a number from that list. I chose the number 8 and used both
if/elif and
while
loops to remove that number from the list and print a new list devoid of instances of 8.
What I found most helpful this week was writing out a verbal translation of the aim of each line of code (a method discussed on the class board). In addition, I would write separate, isolated sections of code to make sure I understood how I would accomplish the goals of each portion of the program. For instance, I was having trouble with one of my
while statements so I opened a new script and worked through various iterations of the statement until the code worked. After doing this with other portions of the code I felt much more confident that I understood how to control the workflow of the bigger picture. I then combined what I learned from these smaller portions of code to write the final program.
I should also mention that this is the first program where I included comments throughout the script. Commenting not only helped me organize my code but I felt that in explaining certain portions of the script it reinforced the concepts we focused on this week. Below you can see a screen shot of the program results.
|
A screen shot of the script I wrote for this module.
It shows the results of a program that runs a dice game,
generates 20 random numbers between 0 and 10,
and removes the number 8 from that list. |
I struggled for a few hours but the pieces fell into place and I felt like something clicked because the solution seemed obvious after the fact. While it is not fun to feel frustrated, solving my issues this week felt like a win. I will also note that we have a class discussion board for this course and that is an incredible resource. I just want to give it some public credit because having a community to reach out to when I am confused is wonderful. I am also a part of a GIS listserv and again, what a great resource. It is nice to know that even though I sit and stare at a screen alone, there are others in my course doing the same thing and we are just a discussion board post away.
#Thanks Programming board!