Monday, May 20, 2024

Python Fundamentals

In this week's assignment, we covered coding basics. I had four bits of code to work on, the result of which is shown below.

The results of my script this week: my last name, followed by the repaired game code, then jumping down to the random numbers at the last three lines.

For part one, we had to create a string that was our name, turn it into a list, and then print out last name from the list. I stumbled a little in getting the string turned into a list that printed words rather than all the separate letters. In reviewing the book and other codes online, it didn’t dawn upon me at first that the split code was using a space to find the places to create the splits. I just thought you had to put quotation marks in the parenthesis for whatever reason. Once I realized that the space was key I was able to make it all happen quickly! 

The second part including fixing a code block for a dice game. This was the hardest step for me. I immediately saw the issue with the case – Dice instead of dice. But it took me a while to understand the issue with turning dice into a string to have it print properly. I guess I learned a lot about types of objects while I read, re-read, and searched the internet for the meaning of the error message I was receiving! 

Part three including writing code to randomly generate a list of 20 integers. This part was a little tedious as well, largely because I kept making dumb mistakes! I was easily able to print a list of 1 randomly generated number but had a time trying to sort out how to make 20 of them. I finally figured out that my big mistake was assigning i as the variable to cap the list, but then kept typing in a 1 in the code block later. Oh boy! I’m still a little confused as to if I have followed the instructions correctly. I have a list of numbers and I have an if/break statement in there. But the code worked just as well before I added this in. I know with coding you can get the same output by using a couple of different methods. 

And finally, part four included creating conditions to find and remove a specific integer from the list we had just created. I felt most confident with part 4 as it seemed the most straightforward. This reinforced the syntax of the language in putting the thing you’re looking at (object), followed by what you want to do to it (method), and then the thing other variable involved (argument). So looking in luckyList to count the times x is there.


Here's a look behind the curtain at what made such a beautiful block of text above.


Saturday, May 18, 2024

Python Environments and Flowcharts

This week kicked off the GIS Programming Course with readings, lectures, and assignments to introduce us to the world of Python. This includes getting to know the basics of python environments, both inside ArcGIS and with external IDES, as well as understanding how to break down coding processes using flowcharts. 


This is a simple flow chart I made to explain the process of calculating degrees from radians


The first assignment including running a simple code to set up our folders for the class. I copied it from the repository to my S drive and ran it in IDLE. Et voila! My folders are ready to go! I was curious to see if I could tweak the code. I usually do not use the Citrix workspace because I have ArcGIS installed on my laptop. I switched the language from the “# Create folders” section to read G:\\GISProgramming as I work from the Google Drive. There’s obviously more going on in the code than I can see as it didn’t work! This also lead me down a rabbit hole of reading about tracebacks.

We also pulled up the Zen of Python to contemplate. I think the poem expresses some of the guiding tenets of Python. From what I have read about the language, it was created to be easy to use with simple syntax that works across platforms and with programs that can interpret the code. Zen leans into these ideas to keep things straightforward and uncomplicated – explicit, sparse, easy and readable. I like that it starts off with beauty though, as simple things can still be beautiful.




GIS Portfolio

To show off all I have learned during my GIS Graduate Certificate program, I created an online portfolio. Click here to check it out.  The ...