Lab 7
Studying Loops
Submit by the end of lab time

Overview

This lab involves studying and explaining different kinds of loops and their use. It ends with a function definition that you write yourself.

Using lab zip folder

Download the zip folder for lab 7. Unzip it and study the four functions in lab7.py.

Questions

Answer the following questions:

  1. Which functions take a list as a parameter?
  2. Which function takes a string as a parameter?
  3. What function adds to a new list and returns the new list?
  4. What function creates a new string and returns it?
  5. If detect_empty is given a list of 5 strings, under what circumstances does it loop less than 5 times? Provide an example.
  6. Does break_count compare every element in the given num_list? Why or why not?
  7. Which function takes a list as a parameter and always loops the number of times equal to the number of items in the list? (hint: there's only one)

New function definition (optional)

As time permits, complete this part in the lab. In any case, include it with assignment 6.

Write a function called censor that takes two parameters. The first parameter is a list of strings. The second parameter is a string. The function should incrementally build and return a copy of the given list with all instances of the second parameter replaced with a string of asterisks, where the number of asterisks is equal to the length of the replaced word (puntuation included). It should ignore punctuation when deciding to remove an instance. Here are examples:

censor(["hello", "don't", "clear"], "dont") ["hello", "*****", "clear"] censor(["hello", "drat", "clear", "drat"], "drat") ["hello", "****", "clear", "****"] censor(["hello", "drat", "clear"], "d'rat") ["hello", "****", "clear"]

You should study and possibly use functions from lab7.py. Consider using a function by simply calling on it within an expression or comparison.

Deliverable

Create a text file called lab7.txt that contains your answers, the new function definition and sample runs that show that it works.

At the top of the lab, provide a statement of your experience with the lab and whether you worked with others.

Submit your lab7.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.