Module 2 GIS Programming: Python Fundamentals

     Hello all, the second week of GIS Programming (4102/5103) was focused on learning the fundamentals of Python. This included topics such as loops, formatting, lists, sets, and many other basic functions/methods used in Python scripting. As I've said before, the Zandbergen (2020) book helped a lot with figuring out how to do a lot of this. This week we were tasked first with creating a set of names and splitting it into a list. This was simple enough and was a good introduction to creating and indexing a list. The harder parts of the assignment were correcting the dice code and creating a randomly generated list using a while loop. 

I've provided my results from the code down below:


    The dice code had two errors, which took me longer than I expected to figure out. The first error was a syntax mistake in a print code that needed to be cast. The second error was simply a capitalized X instead of a lowercase x. I have included a flowchart of the logic behind the dice script. This flowchart of the logic is part of what helped me to figure out the errors since I was able to break down the script and digest it. 


    The code for the randomly generated list and the removal of an unlucky number was the hardest part of the assignment. My main problem was that I needed to define the "i" variable both within the while loop and before it. Once I did this, I obtained a randomly generated list of 20 integers between 0 and 10 by using an if statement to break the loop. The next step involved removing an unlucky number from the list, which was easier for me. I chose my number, tested it to see if it was in the list, counting how many times it appeared if it was, and then used a while loop to remove however many instances occurred of the number. The flowchart below makes the logic of this much easier to understand. 



Thanks for reading!
    Joel Sexson
    


Comments

Popular posts from this blog

Module 5 GIS Programming: Explore and Manipulate Data

Module 6 GIS Programming: Working with Geometries