list of 20 randomly selected numbers between 0 and 10. To accomplish this I used a while loop to
populate an empty list with 20 numbers (generated using the random module). The final portion of code had to eliminate a number from that list. I chose the number 8 and used both if/elif and while
loops to remove that number from the list and print a new list devoid of instances of 8.
What I found most helpful this week was writing out a verbal translation of the aim of each line of code (a method discussed on the class board). In addition, I would write separate, isolated sections of code to make sure I understood how I would accomplish the goals of each portion of the program. For instance, I was having trouble with one of my while statements so I opened a new script and worked through various iterations of the statement until the code worked. After doing this with other portions of the code I felt much more confident that I understood how to control the workflow of the bigger picture. I then combined what I learned from these smaller portions of code to write the final program.
I should also mention that this is the first program where I included comments throughout the script. Commenting not only helped me organize my code but I felt that in explaining certain portions of the script it reinforced the concepts we focused on this week. Below you can see a screen shot of the program results.
A screen shot of the script I wrote for this module. It shows the results of a program that runs a dice game, generates 20 random numbers between 0 and 10, and removes the number 8 from that list. |
#Thanks Programming board!
No comments:
Post a Comment