Individual means that you do it yourself. You won't learn to code if you don't struggle for yourself and write your own code. Remember that while you can discuss the general (algorithmic) way to solve a problem, you should not even be looking at anyone else's code or showing anyone else your code for an individual assignment.
Review the Group Work guidelines on Cavas and/or ask an instructor if you have any questions.
Be sure to spell all function names correctly - misspelled functions will lose points (and often break anyway since no one is sure what to type to call it). If you prefer showing your earlier, scratch work as you figure out what you are doing, please be sure that you make a final, complete, correct last function in its own cell that you then call several times to test. In other words, separate your thought process/working versions from the final one (a comment that tells us which is the final version would be lovely).
Every function should have at least a docstring at the start that states what it does (see Lesson3 Team Notebook if you need a reminder). Make other comments as necessary.
Make sure that you are running test cases (plural) for everything and commenting on the results in markdown. Your comments should discuss how you know that the test case results are correct.
A. Before you code, provide:
random.random
and return a floating-point number between 1 and 7 (based on your answers to the Lesson 17 pre-activity)B. Define a dice
function that:
dice
function should: random.random
functionStart by having your dice
function return a floating-point number between [1, 7) and be sure it works properly before trying to get your code to return an integer.
C. Define a roll_dice_repeat
function that:
n
, which is the number of random numbers to generate roll_dice_repeat
function should: dice
function repeatedlyAfter you have this function working, run this function and then comment on the results. How do the results convince you that your dice
function works?
D. Define a binning
function that:
n
(the number of random numbers to generate) and m
(the number of intervals to divide the range of floating point numbers)binning
function should: random.random
function n
timesm
intervalsNote: This new binning
function should be a more general version of your functions from part 1, so the pseudocode for this binning
function is almost identical to what you have implemented in part 1 (although in one function instead of two). Whereas the dice
function always divided the range of floating point numbers [1, 7) into a range of six intervals [1, 6], the binning
function should call random.random
n
times and convert the numbers from a floating-point number between [0, 1) to an integer between [1, m].
After running the binning
function repeatedly, describe the type of the distribution observed for the random numbers generated, i.e., is there a pattern/trend for the number of random values in each interval?
E. Write a graphical_binning
function that:
graphical_binning
function should: binning
functionRefer back to the Lesson 17 team to review how to make graphs/plots.
F. Modify the graphical_binning
function. The graphical_binning
function from the last step will make it easier to quickly create plots using different input parameters for comparison. However before making any comparisons, you should normalize the range of output values so that the sum of all intervals is the same regardless of the value of n
.
The easiest way to do this is to divide the number of elements in each bin by the total number of values generated. This ensures that the sum of the elements for all bins is 1, and the value for each bin is limited to the range of 0 to 1. Modify your binning function so that the output list is normalized.
G. Run and test your graphical_binning
function to demonstrate that it meets all of the criteria above. Make sure to comment on your results.
In [ ]: