Friday, June 13, 2014

Module 4: Python Fundamentals - Part 2

This weeks assignment involved debugging an existing script as well as writing our own to produce a desired outcome.  A script that was given to us was supposed to produce a simple dice rolling game between several participants, but it had several errors in need of correction.  To fix these errors, the debugging toolbar was used and error messages were interpreted.  Eventually the output was produces as seen above.

We were then required to randomly generate a list of 20 integers between 0-10 and remove a specific 'unlucky' number.  I chose the number 6 as my “unlucky” number, which was removed.  To print the number of times that 6 appeared in my original list, I used the if-elif-else structure.  Using the count method to determine the number of 6’s in the list, I chose the following three conditional outputs:

If there were no sixes, then it would print “This list contains no sixes.”  If there was one six, then it would print “This list contains 1 six, which was removed.”  If there were multiple sixes, then it would print “This list contains (the number of sixes), which were removed.  
I used the while loop and the remove method to remove each six sequentially from the list until the list contained no sixes.  Then the new list with all sixes removed would be printed.

No comments:

Post a Comment