BYU logo Computer Science

To start this assignment, download this zip file.

The following guide pages cover material needed for this assignment:

Lab 3c — Lists

Preparation

1 minute

Download the zip file for this lab, located above. This zip file has code that you will use for this assignment. Extract the files and put them in your cs110 directory in a folder called lab3c.

Warmup

5 minutes

Consider the following code:

if __name__ == '__main__':
    puppies = ['labrador', 'greyhound', 'golden retriever', 'poodle']
    puppies.append('australian sheepdog')
    puppies = []
    puppies.append('goldendoodle')
    print(puppies)

(1) What does the code print?

(2) Using the file puppies.py, step through the code to see what it does.

(3) Discuss with the TA as needed to understand what it does.

Shopping List

10 minutes

In shopping_list.py, you will find a program that is supposed to let you enter a list of items for a grocery list. You finish entering items by entering a blank line (just pressing enter). But this is what it does if you run it:

Enter an item: milk
Enter an item: eggs
Enter an item: butter
Enter an item:
['']

(1) Working with a partner, use the debugger to step through the code and see what is going wrong.

(2) With your partner, fix the code so it works properly.

(3) Discuss what bugs you found and how you fixed them.

Places Visited

15 minutes

Use the file places_visited.py to write a program that asks you to enter places you have visited and then prints those out. You finish entering places by entering a blank line (just pressing enter). The output should look like this:

Enter a place: Oregon
Enter a place: Washington, D.C.
Enter a place: Italy
Enter a place:
I have visited:
- Oregon
- Washington, D.C.
- Italy

The starter code looks like this:

def main():
    # Write code here
    pass


if __name__ == '__main__':
    main()

Start by making a list of the functions you will call inside of main() to decompose the problem:

FunctionParametersDescription
1.
2.

Discuss the functions you would use with the TA, and then write your code.

Puppy Libs

15 minutes

Use the file puppy_libs.py to write a program that asks you to enter a series of verbs ending in ing. The list of verbs ends with a blank line. The program then prints out The puppy is {verb}! for each verb. It ends by printing The puppy is taking a nap.

Here is some sample input and output:

Enter a verb ending in "ing": playing
Enter a verb ending in "ing": jumping
Enter a verb ending in "ing": barking
Enter a verb ending in "ing": eating
Enter a verb ending in "ing": laughing
Enter a verb ending in "ing":
The puppy is playing!
The puppy is jumping!
The puppy is barking!
The puppy is eating!
The puppy is laughing!
The puppy is taking a nap.

The starter code looks like this:

def main():
    # Write code here
    pass


if __name__ == '__main__':
    main()

Start by making a list of the functions you will call inside of main() to decompose the problem:

FunctionParametersDescription
1.
2.

Discuss the functions you would use with the TA, and then write your code.

Afer you write th code, discuss with the TA:

  • What does this program have in common with the places visited one?

Grading

To finish this lab and receive a grade, take the canvas quiz.

We are providing a solution so you can check your work. Please look at this after you complete the assignment. 😊