Monday, May 30, 2016

Python Fundamentals Part 2

GIS Programming - Mod 3

Woohoo!  What a blast.  So far programming in Python is like sitting around playing with a jigsaw puzzle and getting credit for it.  This week's lesson was a bit more complicated.  This week we started with a code that was partially written, with a few mistakes in it.  We had to correct the mistakes for the code to create a dice game based on the players' name length.  

Results of Python Script
After correcting the existing code we then had to use the modules, methods, functions and conditional statements we had learned about in both this week's and previous weeks' lessons to generate a list of 20 random numbers ranging from 0-10, then select one unlucky number to remove from the list and print a statement saying what would be removed and how many times.  That was a very exciting, but extremely intimidating process.  Even after reading the instructions for the assignment twice I still missed a lot of the information and clues that were provided until I went back a third or a forth or even a fifth time.  

I didn't have any difficulties with the portion of the assignment we were required to take notes on; removing numbers from the list.  My difficulties came from the previous section where we had to print statements saying how many, if any numbers were to be removed from the list.
Flowchart of Python Script
 It was a fairly
simple process until my first test came back with the result of removing only one instance of my unlucky number.  That was when I realized  I was gong to need an elif statement in there too, otherwise the sentence would read that it was taking the unlucky number out "1 times." and that wasn't right.  Figuring the syntax out for that was pretty easy, but it took me quite a while to figure out how to express the elif statement in the flowchart.  All the examples I had seen were basically just if/else statements so I had to play with it for a bit to figure out what made sense for the if/elif/else combination. 

Another confusion I had with the flowchart was how to handle not starting at the beginning.  It was left to us to decide if we would include the code that had been provided for us or just start where we created the code ourselves.  I decided to start where I started, but I didn't want to leave the impression where I started was the beginning of the script so after showing we imported random I added a break to the flow line and hoped that would make sense.

While I learned a lot from this lesson I think one of the most important things I learned is that I need to reorganize my previous lessons so certain aspects of them are more easily accessed.  If this week's lesson is any indication it looks like I'll need to go back quite a bit to refresh and clarify how to do certain things.  There is so much to learn in each lesson it just isn't possible to absorb it all at once.

No comments:

Post a Comment