GIS Programming Week 2
This week, I learned the fundamentals of Python. I used what I learned to correct a script supplied to me, and to write my own. I corrected a script that simulates a game of dice played amongst friends, and wrote a script that displays my name and generates a list of 20 random numbers between 0 and 10. It then removes all instances of the number '7' and reprints the list. I wrote my code for this lab in Python IDLE, as I felt it was the easiest to approach. Messing around with the code and syntax, seeing what works and what doesn’t, was a great exercise that helped me understand the Python language and scripting more clearly. I had only a few troubles, mostly syntax errors that were quickly fixed. It was very satisfying finally getting a line to work after many failed attempts. An example of a mistake I had to troubleshoot was when I established the number ‘7’ as the variable to be removed from the list. I used an if or else clause to determine if ‘7’ showed up in the list and the count method to count how many times the number occurred. If it did, I employed a while loop and remove method to remove all instances of ‘7’ and print the new, updated list. However, whenever the 7’s were removed and the new list was printed, it would reprint every time a ’7’ was removed instead of all at once. I realized this was due to me having the updated list under the while loop, so every time it would remove a ‘7’, the list would print. After moving the last line out of the while loop, the new list printed only once with all the 7’s removed, as I had intended. The output of my code is pictured below.

Comments
Post a Comment