Lesson7 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

Design the largest_of_three function that was described in the end of the Lesson7 Team Notebook.

It should:

  • take three numbers as parameters
  • use a Boolean operator to find the largest of the three numbers
  • return the largest of the three values

You should 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. See this website for an example of pseudocode: https://courses.edx.org/c4x/MITx/6.00.1x/asset/files_ps04_files_WhyPseudocode.pdf

Only after completing the pseudocode should you start on the Python code here:


In [ ]:

Write 4 of your own test cases, with rationales for each, then run each of them with a brief interpretation of the results. Beyond the simple "just works" test cases, your tests should contain (at least):

  • one case with 2 equal largest values
  • one case with negative value(s)

part 2

Design the average_of_two_largest function.

It should:

  • take a single number as a parameter
  • use a loop to read in that many numbers
  • return the average of the two largest values entered
  • use Boolean operators (not methods that change the list)

Again, you should 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.

parameter numbers entered two largest numbers average
3 5,7,9 7,9 8

After writing the pseudocode, come up with at least six test cases and the correct output that should be returned:


In [ ]: