Friday, June 6, 2014

GIS 5103 Module 4: Python Fundamentals Part II




Module 4 continued our journey into the basic syntax of Python script.  The assignment this week was a little more complicated than last week.  This time we were given a piece of code composed of a for loop and an if-elif-else conditional that took the form of a dice game.  This code, however, contained two errors.  We had to debug the script by finding and correcting the errors.  Once the script ran without error, we then had to add new script that accomplished a couple of tasks.  First, the script needed to use a while loop to add 20 numbers to a list and then print that list.  The numbers had to be random and between 0 and 10.  The next, multi-step task was to remove a chosen number from the list and print a message detailing the number of times that number was removed.  This I accomplished using the count method (to find how many times the chosen number occurred in the list), an if-elif-else conditional (to determine which message to print) and a while loop (to remove each instance of that number).  The final task for the script was to print the updated list.

This was a challenging but very enjoyable assignment.  At one point (at least), I was confused on how to proceed.  Rather than dig through the text, I searched for relevant Python forums and tutorials for guidance.  As we have already learned, there appears to be a large community of helpful Python coders that have provided much useful information online.

No comments:

Post a Comment