CSCI 150 - Foundations of Computer Science

Spring 2012

Programming Assignment #6

Due: Friday, February 24, 2012 at 10:10 am

Reading assignment:

To be submitted:

All functions should be submitted in a file entitled hw6.py.
  • Page 84, problem 15.
    Implement this program as a function named dierolls().
    Function declaration: def dierolls(n):
    Return values: Returns a list containing the number of counts for each die roll.
    NOTE: Use [0]*13 instead of [0]*12 to initialize your list.
    >>> dierolls(50)
    [0, 0, 3, 2, 3, 2, 5, 6, 9, 8, 4, 6, 2]
    >>> dierolls(100)
    [0, 0, 5, 4, 8, 13, 13, 16, 8, 15, 9, 6, 3]
    >>> dierolls(200)
    [0, 0, 3, 13, 14, 37, 19, 32, 20, 23, 16, 17, 6]
    
  • Page 84, problem 16. Write a function called stumble1() to implement this program.
    Be sure to print your list after every step of the simulation. At the end of the function, it will return the final list. This will cause the final value to be output twice.

    Example 1:
    [0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0]
    [0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0]
    [0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0]
    [0, 0, 0, 0, 0, 1, 2, 1, 0, 0, 0]
    [0, 0, 0, 0, 0, 1, 2, 2, 0, 0, 0]
    [0, 0, 0, 0, 0, 1, 2, 2, 1, 0, 0]
    [0, 0, 0, 0, 0, 1, 2, 2, 1, 1, 0]
    [0, 0, 0, 0, 0, 1, 2, 2, 2, 1, 0]
    [0, 0, 0, 0, 0, 1, 2, 2, 2, 2, 0]
    [0, 0, 0, 0, 0, 1, 2, 2, 3, 2, 0]
    [0, 0, 0, 0, 0, 1, 2, 2, 3, 3, 0]
    [0, 0, 0, 0, 0, 1, 2, 2, 3, 3, 1]
    [0, 0, 0, 0, 0, 1, 2, 2, 3, 3, 1]
    

    Example 2:
    [0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0]
    [0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0]
    [0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0]
    [0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0]
    [0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0]
    [1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0]
    [1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0]
    
  • Page 86, problem 30.
    Modify the provided function eliza by adding at least three question/answer patterns. It will not return any values.

    Additional problems