CSE 110 | Programming Building Blocks

08 Prepare: Checkpoint

Overview

Demonstrate your understand of for loops.

Assignment

Write a Python Program that does each of the following:

  1. Given the following list of items (copy and paste this line into your program):

    
    colors = ["red", "blue", "green", "yellow"]
    

    Use a for loop to iterate through this list one by one and display each item on its own line as follows:

    
    red
    blue
    green
    yellow
    
  2. Use a for loop to display the numbers 1–8, one number on each line as follows:

  3. 
    1
    2
    3
    4
    5
    6
    7
    8
    
  4. Use a for loop to display the even numbers (hint: count by two) 2–20, one number on each line as follows:

  5. 
    2
    4
    6
    8
    10
    12
    14
    16
    18
    20
    

    Sample Solution

    When your program is finished, please view a sample solution of this program to compare your approach to that one.

    You should work to complete this checkpoint program first, without looking at the sample solution. However, if you have worked on it for at least an hour and are still having problems, you may feel free to use the sample solution to help you finish your program.

    Testing Procedure

    Verify that your program works correctly by following each step in this testing procedure:

    1. Verify that the colors display as desired.

    2. Verify that your output for part 2 does not include 0.

    3. Verify that your output for part 2 does not include 9.

    4. Verify that your output for part 3 does not include any odd numbers.

    5. Verify that your output for part 3 starts at 2 and ends at 20.

    Submission

    When complete, please report your progress in the associated I-Learn quiz.