Posts

Showing posts from May, 2020

Lab 2 [GIS5103]: Python Fundamentals

Image
Output from Module 2 Python script This week's lab focused on practicing with data types and fundamental constructs in the Python scripting language, including for and while loops, as well as  if statements. I examined the differences between  functions  and methods , and I additionally learned how to work with lists, strings, and numbers in Python.  The output shown above is for a Python script that performed these tasks: Step 1: Print the last element of a list containing a full name. Step 2: Display the dice rolls of a set of players and their  game status (win, lose, or tie). Step 3: Create a list of 20 random numbers in the range 0 to 10. Step 4: Remove a preset number from a list. A flowchart I sketched as part of Step 4 is shown here: In this case, I have two variables that I initialize prior to entering the while loop. Within the while loop, I continue to remove the preset number from the list based on the number of times it is present in the lis

Lab 1 [GIS5103]: Introducing Python

Image
The screenshot above provides the result of running my first Python script (based on Python version 3.6.8) to automatically generate folders that will be used this semester for organizing the data, scripts, and results in each module of GIS5103 GIS Programming. One of the main take-aways from the lab this week was interpreting " The Zen of Python ", written by Tim Peters, which I summarized as follows: "The Zen of Python" provides 19 guiding principles to consider when writing Python code. A recurring theme across the principles is that LOOKS MATTER – we should strive to write code that is easy to decipher and read. If there is a simple versus clever way to write the code, we should stick with the simple and explicit version, and we should follow this principle with each line of code (i.e., multiple lines of code that are easy to read are better than one complex line). We should also choose variable names that make reading the code easier (e.g., use a variable