Lab 3
Conditionals, Loops and Functions
Due within an hour after lab time or class time

Overview

This lab practices using and defining functions. You will also get a review of conditional statements. All exercises require that you download the zipped folder, unzip it and load the functions.py file in the editor and run it as a module.

Loading functions.py

If you haven't yet, load the functions.py file and run its module. Note that defining the functions doesn't produce any additional output.

Running a function with nested conditionals

  1. Study the outlook function. How many arguments does it take? Explain what values are printed and what value is returned.
  2. Predict what will happen if you type the following:
    1. outlook(80, "high")
    2. outlook(50, "low")
    3. outlook(5, "high")
    Then check your answers.
  3. Modify the outlook function so that the conditional values and the print strings create output messages that are consistent with your personal taste and observations.
  4. Modify the document string so that it describes what the function does
  5. Create test cases for you modified function and run them to show that it works. How many test cases do you need?
  6. (optional if time permits) Use lists of argument values (e.g. [80, 65, 5] and ["high", "low"]) and loops to systematically run the test cases you created.

Modifying a function with a loop

  1. Study the repeated_wish function and run it. How does the function obtain the number of times it should repeat the wish?
  2. Modify the function so that it uses one parameter that specifies the number of times the wish should be bestowed. For example, repeated_wish(4) should print out the wish 4 times. Your function will no longer use the input/assignment statement. You may delete it or comment it out.
  3. Update the document string so that it specifies how the parameter is used.

Writing a new function (optional for lab, required for assignment 3)

  1. Write a new function called varied_wishes. It should take one argument: a list of strings, each representing a positive wish (e.g. "good luck" or "knock 'em dead"). It should then then print out each of the wishes in the list adorned with enthusiastic punctuation (e.g. an exclamation mark) to your choosing.
  2. Add an appropriate document string to your function.

Deliverable

Create a text file called lab3.txt that contains the following:

  1. A statement that summarizes your completion of the assignment, including any collaboration. Your summary should also address the discussion questions in the instructions.
  2. For each of your Python functions and test code:
    1. Listings of your functions and test code (just paste them in the txt file)
    2. Running examples that demonstrate that your python functions work correctly

Submit your lab3.txt file to D2L.

Grading

Your lab submission will be graded using the following rubric:

  • + .5 --- Your submission is clearly formatted.
  • + .5 --- Your submission includes a summary statement and includes how you collaborated.
  • + .5 / 1.0 --- You submitted most of the lab (0.5) or you submitted all of the lab (1.0).
  • + .5 --- Your lab submission is generally correct.

Labs submitted late are subject to a half point penalty.