Lesson9 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 - instructions

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.

part 1: planning and designing BEFORE coding

Copy and paste here the pseudocode that was developed in Model 3 from the Lesson9 Team Notebook. It should:

  • take nothing as a parameter
  • use an ask-before-iterating loop to:
    • ask for the next number in the list
    • add the number to the end of the list
    • ask if there are any more numbers to be added
    • repeat only if the user enters "yes"
  • return the newly built list

A. You should also have a short description in Model 2 from the Lesson9 Team Notebook on calculating the median of a given list. Convert this description to pseudocode for a completely separate median function that:

  • take the list as a parameter
  • returns the median of the list (the middle value from the list)

Your pseudocode should describe the code that you are trying to implement. 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

B. Write at least three test cases for the median function. For each test case, give the correct median value. Your tests should contain (at least):

  • one case with an odd number of list values
  • one case with an even number of list values (where the median is the average of the middle two values)

part 2: coding and testing

Copy and paste here your statistics function from Lesson 8 individual.

C. Write a new build_list function that takes no parameters. It should prompt the user repeatedly for values (ask-before-iterating) and return a list of numbers. Once your function works correctly, write Python code that calls your build_list function before sending that list to the statistics function.


In [ ]:

D. Modify your statistics function to also print the median value. Do not make changes to the rest of your function – they should continue to calculate and print mean, variance, maximum, minimum and mode.

part 3: improved usability

E. When you use your build_list function, you may have been frustrated if you ever accidentally typed a “ye” instead of “yes”. One way to correct this problem is to check that the user enters “yes” or “no”. Modify your build_list pseudocode here so your program checks if the user enters “yes” or “no” to the question. If the user types something else (such as a number), your algorithm should ask the user for another answer, until the user finally enters “yes” or “no”. The first step to designing your pseudocode is to select an appropriate programming construct (sequential, branching, predetermined loops, or unknown number of loops).

F. Modify your build_list function so it waits for a “yes” or “no” answer.

G. Finally, to make your program more user-friendly, modify your build_list function so it accepts one of four answers (not just two): “yes”, “y”, “no”, “n”.

part 4: final code

H. 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
  • median
  • mode
  • standard deviation

Your function does not need to return anything.

(You don't need to copy and paste your build_list funciton since it should be the last code you included before part 4.)


In [ ]:

I. Run your build_list and statistics functions on all your test cases here, to demonstrate that your code works. Don't forget to comment on how you know that your function works correctly.


In [ ]:

J. Give at least three specific examples of scientific applications that would require a user to enter multiple data. For each example, suggest a user-friendly way for the user to indicate they are done entering values (as discussed in Model 3 in Lesson9 Team Notebook).