During Week 2 of GIS Programming, I learned very quickly that I tend to overthink the lab instructions and make things more difficult for myself than necessary! Although I have not had much experience in using Python, I have used various command line based tools as part of my job a computer forensic examiner. I am looking forward to become more versed in Python so I can add that to my computer forensic tool chest as well!
This week, we learned the basics of Python scripting. I took the time to do the separate (non-scored) exercises to help me build my confidence in scripting and using proper syntax. For the Module 2 Lab, we created four different scripts (and later merged them all into one single .py file for simplicity's sake).
The first script we created taught us about lists regarding string names. We set our full names as the variable called "stringName", then split the name into individual names to another list. We learned the importance of indexing as it relates to what item in the list we intend to print.
The second script was a Dice Game with two errors in it. We were asked to identify the two errors in the code. This was my favorite part of this week's lab. I enjoy looking for anomalies or errors in code, because I find that it makes me understand python scripting better overall. I was able to find both errors fairly quickly, but they were not obvious! The lesson I learned from this? One small error can cause an entire script to fail to work!
The purpose of the third script was to generate a list of 20 numbers, between 0-10. We were required to use the "while" loop structure, which would cause the script to run continually until there was a "break" in the code. Creating this script was the most time consuming for me, mainly because I was over complicating things and writing more code than necessary. Even though I had set up the counter properly, I could not stop the "while" loop! I had to join the Office Hours to help me figure this one out!
The four script was much easier to create for me, once I figured out what I was doing wrong in the previous (third) script.With the fourth script, we used a random list of 20 numbers, and then selected an "unlucky number" to be removed from the list. We also included an instruction to print how many times the unlucky number appeared in the list before it was removed from the final version of this list.
Output for the Mod2.py:
No comments:
Post a Comment