Skip to content

Sep 30: Looping over Ranges, Quiz2

Meet in King 248

Learning Objectives

After today's class, you should be able to:

  • Describe the output and purpose of range() and enumerate().
  • Explain the difference of iterating values versus indexes.

Lesson Outline

Activity [25 min]

Quiz2 [25 min]

Your To-Do List

  • Continue working on the Week 6 study guide
  • Submit Part A of PA1 if you haven't already!

Example Code

names = ["emma", "liam", "aisha", "mateo", "sofia", "ravi"]

for name in names:
    print(f"Hello, {name}!")

for i in range(len(names)):
    name = names[i]
    # replace element at index i
    names[i] = name.capitalize()

# Question 4
for name in names:
    name = name.upper()

# Question 8
prices = [19.99, 6.34, 1.00, 12.79, 2.50]