Wednesday, June 3, 2015

GIS Programming: Fundamentals part 2

Hello viewers,
     This weeks post is dedicated to continuing the fundamentals being explored from last week. The assignment this week focused on completing a partially written script working on conditional statements and exploring branching and looping. The specific python functions explored this week were the use of the import function and while, for, if, elif, and else. Continuing from last week the overall objectives for this week were to import new modules, correct script errors, create statements in conjuction with the tools above, and add scripting comments. Lets look at the results from the script, and then explore briefly how it was created.


You can see in the interactive window there are several aspects of this script. The first and largest section is the dice game at the beginning. Essentially this game takes the persons name, looks at the length of their name in letters, then rolls a number between 0 and double the length of letters. If the person rolls a number higher than the amount of letters in their name, they win, else they lose. The block of code for the game was already written but required me to evaluate it for errors.
The next segment is the list of 20 numbers just below the dice game. This was derived from a block of code taking an empty list, and populating it with the numbers 0-10 at random. It also involved the random module with random integer generation, and a while loop to continue to add to the list until it had 20 numbers, then displaying the final list. The last segment was particularly tricky for me, and I found myself over-complicating my code multiple times. I began with for loops, with while loops, and if / else statements all together. Ultimately after much trial and error I simplified it down to defining a couple key variables up front, then added if, and else conditional statements designed to either tell you there is none of a particular number in the list, or remove that number and tell you how many of them were removed before showing the new list. This was a difficult challenge at first, and I felt befuddled during the last section for sure, and then ultimately was amazed at how simple the finalized solution really was compared to my initial thoughts. Thanks for coming and viewing my continuing Python experience.

No comments:

Post a Comment