Wednesday, May 28, 2025

Module 2 - Python Fundamentals

 

Results of the Module 2 Script
Results of the Module 2 Script. 
 
Flowchart for Creation of the Module 2 Script


GIS programming has proven to be the utmost challenge yet! We are here to rise to the challenge. This week introduced us to GIS basics, from syntax to while and for loops; we dove in deep. 

The initial steps of the assignment were fairly intuitive; it was not until step 3 that the fun really began. A description of my processes for steps 3 and 4 is seen below. 

Step 3: Create a loop that adds 20 random numbers between zero (0) and ten (10) to a list

 

The first step was to import the random module because the instructions specifically asked for a random number. **Like rolling dice.

Assign the lucky list to be empty so that it can be filled in later.

Next is the while loop-

Set counter as indicated, start at zero,

We used the append function because that would instruct us to add the numbers to the empty luckyList. 

We set the while i < 20 because this is how many iterations we want until the loop equals false and stops

Then we used the append method to add the random integers, from ranges 0-10, to the empty list.

We really did not need to, but the instructions asked us to, so we included an if and break statement that would prevent the list from going further than 20 iterations.

 

Then we hit print luckyList so that we could print out a list as requested.

 

***Using a for loop would have been a better, more concise option.

 

Step 4: Create a loop that removes an unlucky number from the list generated in step 3.

 

For this step, I began by copying luckyList, generated in step 3, into the cell.

Then an integer is assigned to the variable x.

Created an if statement where if it was not equal to x, it would say that it was not in the loop. However, if it were, the else statement could invoke the count method to count how many times that integer occurred in the list

Then, creating a print statement that mentioned how many times a specific number was to be removed was rather confusing, and I had to do some external research. I first had to write out the statement with parentheses and variables within, for example, (x) and (count). I had to write a count assignment statement just like I did for x.

Finally, the creation of the while loop using the remove method was used to remove the unlucky variable x from the previously generated list.  I struggled with the creation of this loop because I did not write the remove method on the same line that mentioned the lucky list. Therefore, every time I tried to print the while loop, an error would appear saying that x did not appear in the list.

Finally, the updated luckyList with no variable x was printed.

 

No comments:

Post a Comment

Module 5- Exploring and Manipulating Data

Figures 1-4: Creating a File geodatabase and copying data into it. Flow chart denoting the cradle to grave process of creating a file geodat...