Sunday, June 8, 2014

GIS4102 Module 4: Python Fundamentals Part II

The focus of this week's exercise and assignment was continuing practice of and developing familiarity with Python scripting. The emphasis was on importing modules, troubleshooting code (many opportunities arise for this in my particular case), creating while loops and conditional statements, adding comments, and iterating variables within loops. The first portion of the assignment involved the import of a module and troubleshooting the code provided for a dice game with random number generation.

The script-creating portion of this assignment included developing a while loop to add 20 random integers between 0 and 10 to a list. From that list one number was eliminated and the number of times it had occurred was printed in a message. For random-generations in which the number did not occur, a different message was printed. The screenshots included here show an example of each message:
The Number 5 Eliminated from List
and Associated Message
The Number 5 Does Not Occur in List
with Associated Message
The error message returned at the second while loop I initially coded was a bit deceptive, notifying me that my variable was not in the list although it could be printed out. After trying to troubleshoot it in one manner, I finally tried another tactic which solved the problem. Those while loops certainly do want to have an exit condition in order to process.

Throughout the script, descriptive comments were added. After the script was completed, header comments were included to identify the script name, author, date, and a brief description of the script. This was a great practice exercise and assignment.

No comments:

Post a Comment