Module 2 - Python Fundamentals

 This module was a direct expansion on the previous module, however far more in-depth. With the use of for-else statements, various methods and functions, for/while loops, and variable/list assignment I was asked to complete a set of tasks to achieve a fully-fledged script. My script needed to achieve the following:

1) Print my last name from a created list

2) Have corrected errors from a prewritten code set

3) Populate an empty list with 20 random integers

4) Remove an "unlucky" number from the previously created list

Step 1 included mainly utilizing string assignment and simple function to print my name. For step 2, I was given a set of prewritten code and successfully corrected two syntax errors to get the code to run correctly. Steps 3 and 4 built off of each other and required a far more complex set of functions and methods within various loop structures. With some tenacity I was able to complete each step and get my script to return the following:


The image above is the result of running my final script in ArcGIS Notebooks. The first two lines are the result of step 1. The line involving specific names are the result of the corrected prewritten code set in which a dice game is played based on a list of names using an if-elif-if statement. The last three lines are the results of steps 3 and 4. The first of these lines is a list created based on a while loop creating a random integer between 0 and 10 20 times. The last two lines are the result of using an if-else statement as well as a "while" loop to see if the number 10 shows up in the first list and how many times it has been removed if so.

For a better understanding of just how my script works, take a look at this flowchart:


 

Admittedly, this flowchart is not perfect and I need more practice making flowcharts. However, I believe the column of processes on the right hand side accurately depicts the order of processes in the script based on an if-else statement.

Finally, here are some notes I took based on my experience with the assignment:

-Began by copying all resources from the R drive for Module 2 and getting them on my S drive. This was a breeze given the processes completed in Module 1 lab
-When splitting my name into a list, it seemed counterintuitive that the split method needed no argument in the parentheses. However, it seems to be a special case which in turn makes it easier to remember.
-Correcting the errors in step 2 was quite easy after the lecture material. It seems like one of the most common errors in Python is when 2 different types of data are attempted to run together in the same function. After running the script it became obvious that dice, which was previously set as an integer, needed to be changed into a string to run the print function properly. The other error was far more  simple, as case sensitivity is a very real thing in Python so the capital “X” needed to become a lowercase “x” for the script to associate x as the assigned variable throughout the script.
-The language of loops is something that will take me some time but realizing that the “else” portion of an if statement basically means the opposite of what was coded in the “if” statement.

Comments