Lesson8 Individual Assignment

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. Ask an instructor if you are really stuck and having very specific code problems.
Review the Group Work guidelines on Cavas and/or ask an instructor if you have any questions.

Programming Practice

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.

part 1: planning and designing BEFORE coding

Pseudocode

Start with the statistics pseudocode that was developed in the Lesson8 Team Notebook. It should:

  • take a list of numbers as a parameter
  • use the same loop to calculate and print:
    • the mean (Model 1)
    • the variance (Model 1)
    • the maximum value (Model 2)
    • the mode (Model 4: requires nested loops)
  • currently does not return anything

Modify this pseudocode by so your function now also:

  • calculates and prints the minimum value
  • calculates and prints the standard deviation

Now provide pseudocode (a mix of English and Python code) that describes the code that you are trying to implement. Your pseudocode should be clear about whether you plan to use if-statements, while-loops, or for-loops for this function. Remember the code formatting tricks, and see the website for an example of pseudocode: https://courses.edx.org/c4x/MITx/6.00.1x/asset/files_ps04_files_WhyPseudocode.pdf

Test cases

Write at least four of your own test cases. For each test case, give the correct mean, variance, maximum and minimum values, mode, and standard deviation. Your tests should contain (at least):

  • one case with all positive value(s) with some duplicate numbers
  • one case with both positive and negative value(s) with no duplicates
  • one case with all negative value(s)
    (it's a good idea to have some lists with several-many values)

Also comment on the logic of your test cases as well as where you got the correct answers from.

Now find your Python code developed in Model 1 of the Lesson8 Team Notebook. It should only calculate the mean. List the order of the calculations that you will be adding and testing. (There are many reasonable answers.)

part 2: coding and testing

As you code your statistics function, you should add one feature at a time. You should test your function on all your test cases and confirm that the all the calculations work correctly before moving on to the next statistics function. You should show the progression of your statistics function here.


In [ ]:

part 3: final code

Finally, give your complete, working statistics function here, which should take a list of numbers as a parameter and calculate and print the following in a user-friendly way (i.e., you should print more than just a list of numbers):

  • mean
  • variance
  • maximum
  • minimum
  • mode
  • standard deviation

Your function does not need to return anything.


In [ ]:

Run your statistics function on all your test cases here, to demonstrate that your code works.