Module 1 - Python Fundamentals

 

Code Output from Lab 1 Components
Commence GIS Programming! This introductory module focused on the basics of the Python programming language and programming functionalities within GIS software. I am very excited to gain a better handle on Python throughout this course, as I am well aware of its usefulness in a variety of positions and tasks. 

This week's laboratory assignment consisted of four separate parts that all utilized various elements of the Python language. 
For part one, we were tasked with assigning our name to a list and then separating the first and last name, and then printing our last name. I found this to be the easiest portion of the assignment and had relative ease using the necessary function to separate my name. 
The second task involved resolving a pre-written code's errors to get the code to run. For this part, I combed through the code with a fine-tip comb, seeking for any and all errors that would result in the code not being able to run properly. Without revealing the errors, I will say this portion took a bit more time, as some codes can have the smallest error result in absolutely none of the code executing properly. 
The third part involved creating a list that would consist 20 random integers 1-10. I was able to create a while loop with a nested if/else statement to cycle through each index of the list and assign it a random integer using the randint() method. The syntax of the code was new to me, as I have only had experience with Java which is a bit different. 
For the last portion of the laboratory assignment, I assigned a number to the unlucky number variable,  created a message, and removed it from the created list. This was certainly the most complex portion of the assignment and required a great amount of critical thinking to accomplish. First, I began step 4 by assigning a value to a variable (unluckyNum) and chose the integer 5. This means that whenever the number 5 was generated in the list, it could be called upon as the unluckyNum variable. I then constructed an if else loop that would cycle through the code until all instances were accounted for. Doing so ensured that the program would repeat until all indexes were checked. I used the count method to check each index for the unlucky number (5) and total the amount of times the unlucky number was found in the list. The if else loop would then check for this number at each index. If the ‘if’ statement were to come true (i.e. the list did not contain the number), then I created a string + value combination output that would tell the user the unlucky number of five was not found in the created list. The exact opposite was done in the else scenario, however I added the count method to the output. Doing so allows the user to see how many times the unlucky number was found in the list. Lastly, to physically remove the unlucky integer from the list, I created a while loop. This loop was iterated 20 times, or the amount of index items in the list, with the use of the len function. I used a for statement to set the parameters for what would be removed Then I called upon the remove method to remove all instances of the unlucky number found in the list. This method works by choosing the argument (in this case, 5) and then it actually goes in and removes it from the list. I used an else statement to tell the program to iterate again. This would ensure all instances of the unlucky number were removed. Lastly, I used the print function to print the string again. I did this so that the user could see the string again without any instances of the unlucky variable.

One difficult concept for me to learn was that the different variable types must be accounted for when using certain methods and functions. For example, when I was trying to print whether or not the unlucky number was in the list and how many times, I had to navigate re-casting certain elements of that output (for example str( )). This was a bit confusing to me at first, but I am slowly getting the hang of Python and its inner-workings.

This module was certainly quite a bit of new information for myself and I am glad I got started early in the week with the lecture content. I find that learning how to write scripts really is like learning a whole new language. While I have certainly faced a learning curve, after completing the lab assignment I feel much more confident in myself and my programming abilities. I think the most important part of the programming process for me is to consult in outside resources and ask for help. Overall, I had great success in this first laboratory assignment of the GIS programming class. I was able to get my code running properly and have the output be exactly what the assignment required. I will certainly have to work more with Python to better understand the different syntax requirements, but otherwise I think I will quickly catch on and be able to utilize Python to enhance my geospatial skills.