Introduction
The purpose of this in-class activity is to practice
creating and working with lists and to iterate through lists.
Exercises
- Read through the following sections from the Runestone book,
working through the exercises in the readings:
- Section 7.5: Lists and
for
loops.
- Section 7.6: The Accumulator Pattern.
- Section 7.7: Transversal and the
for
loop: By
Index.
- Create a new notebook in Google Colab to contain your code for the
following exercises. Each exercise should be in a new Code cell.
- Create a list containing the names of at least 10 of your family members. (You
could include your parents, sibblings, grandparents, aunts, uncles,
cousins, etc.) Then
write statements for the following:
- Use an appropriate index to print the first element of your list.
- Use an appropriate index to print the last element of your
list.
- Use list traversal to print out all elements of your list.
- Use a
for
loop and indexing to print out all elements of
your list.
- Create a list of the integers from 0 to 100 and assign that
list to the variable
numbers
. Use a Python function to
create the list - do not type out the whole list yourself!
Then write statements for the following:
- Print out the middle element of your list. You should use
the
len
function in your index.
- Use a
for
loop to sum the elements of your
list. Then print out that sum.
- Create a list of at least 10 high temperature readings
recorded at the Kalamazoo/Battle Creek International Airport
Station in the month of September. Weather
History. Then write statements for the following:
- Use a
for
loop and an if
statement
to find the total number of temperatures in your list that were
over 80 degrees. (Or over 70 degrees, or some other threshhold
you determine makes sense.) Print out that total.
- Write statements to calculate the average temperature from
your list. (How do you calculate the average? Sum up the
values, and then divide by the number of value.) Print the
average temperature.
Submit
When you are satisfied with your statements, add your name, the date, and a
description of this activity in a Text cell at the beginning of your
notebook and then submit the file you created for this activity
via
Kit.