Friday, June 5, 2015

Python Fundamentals II - A Dice Rolling Game

We continue our journey through the world of Python. This week we picked-up where we left off last week with Python Fundamentals. Learning a new language takes time and practice. I put in quite a bit of time this week and I now have a better understanding about Python and functions, and methods, and syntax, but I still have a long road to travel.

For this week in GIS 5103 Programming, I created a scrip that runs a dice rolling game based on the players’ name length, then it creates a list with 20 random numbers in it. It also has a conditional statement with a nested while loop that removes all instances of an “unlucky” number (I selected 6) from the list. Below I explain one of the steps in my script-writing process.

Removing numbers from my list.
1.      To remove a number from a list, the command is: number.remove(specify the number)
2.      For my script, I created a “list” so my remove command looked like: list.remove(specify the number)
3.      I previously defined my “unlucky” number as the variable “k”, so I wanted “k” removed from the list: list.remove(k).
4.      However, the command “remove” only removes the first occurrence. Therefore, I had to define a loop
5.      To define the loop, I used: 
q = 1
while q <=20
k=6
list.remove(k)

Notes on my progress:
1.      I had numerous issues with this script: I created several infinite loops (Remember to use “break” or define that loop with the “sentry” on top)
2.      My script disappeared from my S-drive for unknown reasons: I saved my script on my home desktop and could open it using Notepad. This must become first nature for me

3.      There are many ways to write a script; I have a lot to learn



No comments:

Post a Comment