::: {#navbar .navbar .navbar-default .navbar-fixed-top role="navigation"}
::: {.container}
::: {.navbar-header}
[]{.icon-bar} []{.icon-bar} []{.icon-bar}

<div>

[![](../_static/img/RAIcon.png)](/runestone/default/user/login){.brand-logo}
[fopp](../index.html){#rs-book-toc-link .navbar-brand}

</div>
:::

::: {.navbar-collapse .collapse .navbar-ex1-collapse}
-   
-   []{#ad_warning}
-   []{#browsing_warning}
-   
-   [*[Search]{.visuallyhidden
    aria-label="Search"}*](#){.dropdown-toggle}
    -   [Table of Contents](../index.html)

    -   [Book Index](../genindex.html)

    -   

    -   ::: {.input-group}
        :::
-   
-   [*[User]{.visuallyhidden aria-label="User"}*](#){.dropdown-toggle}
    -   []{.loggedinuser}

    -   

    -   [Course Home](/ns/course/index)

    -   [Assignments](/assignment/student/chooseAssignment)

    -   [Practice](/runestone/assignments/practice)

    -   [[Peer Instruction
        (Instructor)](/runestone/peer/instructor.html)]{#inst_peer_link}

    -   [Peer Instruction (Student)](/runestone/peer/student.html)

    -   

    -   [Change Course](/runestone/default/courses)

    -   

    -   [[Instructor\'s
        Page](/runestone/admin/index)]{#ip_dropdown_link}

    -   [Progress Page](/runestone/dashboard/studentreport)

    -   

    -   [Edit Profile](/runestone/default/user/profile){#profilelink}

    -   [Change
        Password](/runestone/default/user/change_password){#passwordlink}

    -   [Register](/runestone/default/user/register){#registerlink}

    -   [Login](#)

    -   ::: {.slider .round}
        :::

        Dark Mode
-   
-   [[*[Scratch Activecode]{.visuallyhidden
    aria-label="Scratch Activecode"}*](javascript:runestoneComponents.popupScratchAC())]{#scratch_ac_link}
-   
-   [*[Help]{.visuallyhidden aria-label="Help"}*](#){.dropdown-toggle}
    -   [FAQ](http://runestoneinteractive.org/pages/faq.html)
    -   [Instructors Guide](https://guide.runestone.academy)
    -   
    -   [About Runestone](http://runestoneinteractive.org)
    -   [Report A
        Problem](/runestone/default/reportabug?course=fopp&page=Exercises)
-   

```{=html}
<!-- -->
```
-   
-   [This Chapter](../index.html){.dropdown-toggle}
    -   [7.1 Introduction: Iteration](intro-Iteration.html){.reference
        .internal}
    -   [7.2 The for Loop](TheforLoop.html){.reference .internal}
    -   [7.3 Flow of Execution of the for
        Loop](FlowofExecutionoftheforLoop.html){.reference .internal}
    -   [7.4 Strings and for loops](Stringsandforloops.html){.reference
        .internal}
    -   [7.5 Lists and for loops](Listsandforloops.html){.reference
        .internal}
    -   [7.6 The Accumulator
        Pattern](TheAccumulatorPattern.html){.reference .internal}
    -   [7.7 Traversal and the for Loop: By
        Index](TraversalandtheforLoopByIndex.html){.reference .internal}
    -   [7.8 Nested Iteration: Image
        Processing](NestedIterationImageProcessing.html){.reference
        .internal}
    -   [7.9 👩‍💻 Printing Intermediate
        Results](WPPrintingIntermediateResults.html){.reference
        .internal}
    -   [7.10 👩‍💻 Naming Variables in For
        Loops](WPNamingVariablesinForLoops.html){.reference .internal}
    -   [7.11 The Gory Details:
        Iterables](GeneralizedSequences.html){.reference .internal}
    -   [7.12 👩‍💻 Keeping Track of Your Iterator Variable and Your
        Iterable](WPKeepingTrackofYourIteratorVariableYourIterable.html){.reference
        .internal}
    -   [7.13 Glossary](Glossary.html){.reference .internal}
    -   [7.14 Exercises](Exercises.html){.reference .internal}
    -   [7.15 Chapter Assessment](week2a2.html){.reference .internal}
-   
-   
:::
:::
:::

::: {#continue-reading .container}
:::

::: {#main-content .container role="main"}
::: {#adcopy_1 .adcopy style="display: none;"}
#### Before you keep reading\...

Runestone Academy can only continue if we get support from individuals
like you. As a student you are well aware of the high cost of textbooks.
Our mission is to provide great books to you for free, but we ask that
you consider a \$10 donation, more if you can or less if \$10 is a
burden.

::: {.donateb}
[Support Runestone Academy Today](/runestone/default/donate?ad=1){.btn
.btn-info}
:::

::: {#adcopy_2 .adcopy style="display: none;"}
#### Before you keep reading\...

Making great stuff takes time and \$\$. If you appreciate the book you
are reading now and want to keep quality materials free for other
students please consider a donation to Runestone Academy. We ask that
you consider a \$10 donation, but if you can give more thats great, if
\$10 is too much for your budget we would be happy with whatever you can
afford as a show of support.

::: {.donateb}
[Support Runestone Academy Today](/runestone/default/donate?ad=2){.btn
.btn-info}
:::
:::
:::

::: {#exercises .section}
[7.14. ]{.section-number}Exercises[¶](#exercises "Permalink to this heading"){.headerlink}
==========================================================================================

::: {#q6_11_1 .full-width .container .question component="question" question_label="7.14.1"}
4.  ::: {.runestone .explainer .ac_section}
    ::: {#ex6_11_1 component="activecode" question_label="7.14.2"}
    ::: {#ex6_11_1_question .ac_question}
    In Robert McCloskey's book *Make Way for Ducklings*, the names of
    the ducklings are Jack, Kack, Lack, Mack, Nack, Ouack, Pack, and
    Quack. This loop tries to output these names in order.

    Of course, that's not quite right because Ouack and Quack are
    misspelled. Can you fix it?
    :::
    :::
    :::
:::

::: {#q6_11_2 .full-width .container .question component="question" question_label="7.14.3"}
5.  ::: {.runestone .explainer .ac_section}
    ::: {#ex6_11_2 component="activecode" question_label="7.14.4"}
    ::: {#ex6_11_2_question .ac_question}
    Get the user to enter some text and print it out in reverse order.
    :::
    :::
    :::
:::

::: {#iter_ex_3 .full-width .container .question component="question" question_label="7.14.5"}
6.  ::: {#q3 .alert .alert-warning component="tabbedStuff"}
    ::: {component="tab" tabname="Question"}
    ::: {.runestone .explainer .ac_section}
    ::: {#ex_3_3 component="activecode" question_label="7.14.6"}
    ::: {#ex_3_3_question .ac_question}

    Write a program that uses a for loop to print

    :   ::: {.line-block}
        ::: {.line}
        `One of the months of the year is January`{.docutils .literal
        .notranslate}
        :::

        ::: {.line}
        `One of the months of the year is February`{.docutils .literal
        .notranslate}
        :::

        ::: {.line}
        `One of the months of the year is March`{.docutils .literal
        .notranslate}
        :::

        ::: {.line}
        etc ...
        :::
        :::
    :::
    :::
    :::
    :::

    ::: {component="tab" tabname="Answer"}
    ::: {.runestone .explainer .ac_section}
    ::: {#q3_answer component="activecode" question_label="7.14.7"}
    ::: {#q3_answer_question .ac_question}
    :::
    :::
    :::
    :::

    ::: {component="tab" tabname="Discussion"}
    [Show Comments](#disqus_thread){.disqus_thread_link}
    :::
    :::
:::

::: {#iter_ex_4 .full-width .container .question component="question" question_label="7.14.8"}
7.  ::: {.runestone .explainer .ac_section}
    ::: {#ex_3_4 component="activecode" question_label="7.14.9"}
    ::: {#ex_3_4_question .ac_question}
    Assume you have a list of numbers
    `12, 10, 32, 3, 66, 17, 42, 99, 20`{.docutils .literal .notranslate}

    1.  Write a loop that prints each of the numbers on a new line.

    2.  Write a loop that prints each number and its square on a new
        line.
    :::
    :::
    :::
:::

::: {#iter_ex_6 .full-width .container .question component="question" question_label="7.14.10"}
8.  ::: {.runestone .explainer .ac_section}
    ::: {#ex_3_6 component="activecode" question_label="7.14.11"}
    ::: {#ex_3_6_question .ac_question}
    Write a program that asks the user for the number of sides, the
    length of the side, the color, and the fill color of a regular
    polygon. The program should draw the polygon and then fill it in.
    :::
    :::
    :::
:::

::: {#iter_ex_7 .full-width .container .question component="question" question_label="7.14.12"}
9.  ::: {#q7 .alert .alert-warning component="tabbedStuff"}
    ::: {component="tab" tabname="Question"}
    ::: {.runestone .explainer .ac_section}
    ::: {#ex_3_7 component="activecode" question_label="7.14.13"}
    ::: {#ex_3_7_question .ac_question}
    A drunk pirate makes a random turn and then takes 100 steps forward,
    makes another random turn, takes another 100 steps, turns another
    random amount, etc. A social science student records the angle of
    each turn before the next 100 steps are taken. Her experimental data
    is `160, -43, 270, -97, -43, 200, -940, 17, -86`{.docutils .literal
    .notranslate}. (Positive angles are counter-clockwise.) Use a turtle
    to draw the path taken by our drunk friend. After the pirate is done
    walking, print the current heading. Assume that the turtle
    originally has a heading of 0 and accumulate the changes in heading
    to print out the final. Your solution should work for any sequence
    of experimental data.
    :::
    :::
    :::
    :::

    ::: {component="tab" tabname="Answer"}
    ::: {.runestone .explainer .ac_section}
    ::: {#iter_q7_answer component="activecode" question_label="7.14.14"}
    ::: {#iter_q7_answer_question .ac_question}
    :::
    :::
    :::
    :::

    ::: {component="tab" tabname="Discussion"}
    [Show Comments](#disqus_thread){.disqus_thread_link}
    :::
    :::
:::

::: {#iter_ex_8 .full-width .container .question component="question" question_label="7.14.15"}
10. ::: {.runestone .parsons-container}
    ::: {#pp_3_8 .parsons component="parsons"}
    ::: {.parsons_question .parsons-text}
    Write a program that will go through a list of temperatures and
    print them out to the user.
    :::

    ``` {.parsonsblocks question_label="7.14.16" style="visibility: hidden;"}
            temperatures = [-3, 78, 95, 28, 56, 42, 56, 81, -10, -]
    ---
    for temp in temperatures:
    ---
        print("The weather outside is: " + str(temp))
            
    ```
    :::
    :::
:::

::: {#iter_ex_9 .full-width .container .question component="question" question_label="7.14.17"}
11. ::: {.runestone .parsons-container}
    ::: {#pp_3_9 .parsons component="parsons"}
    ::: {.parsons_question .parsons-text}
    Write a program that will print out a greeting to each student in
    the list. This list should also keep track of how many students have
    been greeted and note that each time a new student has been greeted.
    :::

    ``` {.parsonsblocks question_label="7.14.18" style="visibility: hidden;"}
            students = ["Jay", "Stacy", "Iman", "Trisha", "Ahmed", "Daniel", "Shadae", "Tosin", "Charlotte"]
    ---
    num_students = 0
    ---
    for student in students:
    ---
        print("Welcome to class, " + student)
    ---
        num_students += 1
        print(str(num_students) + "student(s) have entered the classroom")
            
    ```
    :::
    :::
:::

::: {#contributed-exercises .section}
[7.14.1. ]{.section-number}Contributed Exercises[¶](#contributed-exercises "Permalink to this heading"){.headerlink}
--------------------------------------------------------------------------------------------------------------------
:::
:::

::: {style="width: 100%"}
::: {ea-publisher="runestoneacademy" ea-type="image" style="display: flex; justify-content: center"}
:::
:::

::: {#scprogresscontainer}
You have attempted []{#scprogresstotal} of []{#scprogressposs}
activities on this page

::: {#subchapterprogress aria-label="Page progress"}
:::
:::

-   [[](Glossary.html)]{#relations-prev}
-   [[](week2a2.html)]{#relations-next}
:::

::: {.container}
[]{#numuserspan}[]{.loggedinuser} \| [Back to top](#)

© Copyright 2017 bradleymiller. Created using
[Runestone](http://runestoneinteractive.org/) 7.2.10.
:::
