Wednesday, May 29, 2024

Python Fundamentals - GIS Programming Module 2

 Hello everyone!

In this week's lab, we explored some of the basic fundamentals of Python to help prepare us for what is coming ahead in this course. At the end of the assignment, we were expected to know how to run Python scripts using Notebook in ArcGIS Pro. While using Notebook we needed to work with string variables, so in the lab, we had to identify our full name with a string variable and the string looked like this: stringName = 'Tyler Scott Weber'. The next learning outcome we were supposed to achieve was to use and import modules, this was very important for the overall final result of the lab. The one module we had to import was the random module, so at the beginning of the line of code for our random number generator, the first thing that needed to be done was to type import random. We needed to learn how to save Python code as a script for the next objective. This can be done by simply exporting the code from Notebook and then saving the script as a .py file. For the next object, we needed to know how to include comments in the scripts, this is done by using a # for each line that the comment is located on. The comments are important for users because they can give context to what the code is trying to portray. The last two learning outcomes are being able to create loops and conditional statements and then iterate variables within loops to control script workflow. 

These outcomes were key to learning to finalize the lab submission. But to give you an idea of what the lab assignment entailed; we were tasked with printing our last name from a created list and then using indexing to print our last name from another list containing our full name. The next step gave us a bit of pre-written code for a dice game that had two errors, the first error was fixing the code to print the random number that the dice showed. The issue with it is that we couldn't use a str() because the code is part of a module. The next issue that was wrong with the text was that an x was capitalized when it needed to be lowercase. For the 2nd half of the lab, we needed to create a random number generator, the lecture exercises were key to the success of this part of the lab. Some notes I took included examples of a different formatted random number generator and different ways we can display a limited range of the number generator. I had to explore the range aspect because we need to display 20 random numbers between or equal to 0 and 10.  Here is a flowchart of the code I wrote to give you an idea of how the script is read:



Without further ado, here is the result of my script from the overall assignment:


This week's lab was a great wake-up call on what to expect moving forward, and I am excited to see what will come next.

Thanks for reading!






No comments:

Post a Comment

Final Project and other maps created

 After eight weeks this class has come to its conclusion. Our last task was to come up with a project idea that is geographic and meaningful...