A software development philosophyFirst document your code by writing the tests it must satisfy, then write the code.In python, doctest makes this easySee the doctest example, then write a program.TaskWrite a function add_dice that takes two lists of values corresponding to the numbers on two dice, and that returns the probability distribution of the sum of the two dice. Write this function using the doctest approach. First write the documentation, including several examples, such as: >>> add_dice( [1, 2, 3, 4], [1, 2, 3, 4] ) >>> add_dice( [1, 2, 2, 3], [1, 3, 3, 5] ) >>> add_dice( [1, 2, 3, 4, 5, 6], [1, 2, 3, 4, 5, 6] ) You might find the convolve function useful when solving this problem. See this page for example functions using scipy.convolve. But it's not essential to use convolve. When you have written your program, check that you get the correct answer for the solution to Alan's problem, find another labelling of two six-sided dice, such that the sum has the same distribution as add_dice( [1, 2, 3, 4, 5, 6], [1, 2, 3, 4, 5, 6] ) . Further examplesWorked solution |
|