Week 12
Loop before you Leap (Loops, part 2)

Weekly Summary

Recall from our last week that that we reminded ourselves of the definition of loops as:

This week we will expand our work to include loops that process Strings (an ordered sequence of characters) and Lists (an ordered sequence of data). These are not only common data structures in programming, but are often the types of data structures that "require" the use of loops in order to most efficiently solve the problems.

 

Learning Outcomes

By the end of the week students should be able to:

  • Explain and/or properly use the following details of working with Strings and Lists:
    • How to identify the length of a String or list using - len()
    • How to identify a single item in a String or a List using indices - myString[index] or myList[index]
    • How to access a slice of items in a String or a list - myString[index1:index2] or myList[index1:index2]
    • How to create an empty list - mylist = []
    • How to create an empty String - myString = ""
    • How to "add to" a list - myList.append(newItem)
    • How to "add to" a String - myString = myString + newString
  • Reading Code
    • Given a snippet of code that includes a String, indicate the results of the code.
    • Given a snippet of code that includes a List, indicate the results of the code.
  • Writing Code
    • Given a problem statement that includes the name of a function and the parameters required by that function, write the Python code/definition of the provided function such that it solves the problem by returning correct output values.
  • Debugging Code
    • Given a problem statement and a non-working Python function that attempts to solve the problem, identify where the function is incorrect and explain how to fix it.

 

Learning Materials

This week you will complete the following activities

 

Additional Practice

The following problems are entirely optional but are provided here to give you some additional practice if you are interested. You should complete these on your own rather than with a partner.

 

Graded Practice

The following programs are formally graded as part of the Unit 3 "Problem Set." You should work on these only as an individual. While working on these problems you may refer to your notes, your textbook, any programs you wrote, and even my videos. However, you should limit your discussion of these programs with classmates. It is acceptable to discuss how you solved a problem in grand scheme of things, but you should never show your code to a classmate either as the person who is struggling or as the person who is helping a struggling classmate. You can talk ideas, but not specific solutions.