::: {#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}
    -   [14.1 Introduction](intro-indefiniteiteration.html){.reference
        .internal}
    -   [14.2 The while Statement](ThewhileStatement.html){.reference
        .internal}
    -   [14.3 The Listener Loop](listenerLoop.html){.reference
        .internal}
    -   [14.4 Randomly Walking
        Turtles](RandomlyWalkingTurtles.html){.reference .internal}
    -   [14.5 Break and Continue](BreakandContinue.html){.reference
        .internal}
    -   [14.6 👩‍💻 Infinite Loops](WPInfiniteLoops.html){.reference
        .internal}
    -   [14.7 Exercises](Exercises.html){.reference .internal}
    -   [14.8 Chapter Assessment](ChapterAssessment.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}
[14.7. ]{.section-number}Exercises[¶](#exercises "Permalink to this heading"){.headerlink}
==========================================================================================

::: {#moreiter_ex_1 .full-width .container .question component="question" question_label="14.7.1"}
1.  ::: {#q1 .alert .alert-warning component="tabbedStuff"}
    ::: {component="tab" tabname="Question"}
    ::: {.runestone .explainer .ac_section}
    ::: {#ac14_9_1 component="activecode" question_label="14.7.2"}
    ::: {#ac14_9_1_question .ac_question}
    **1.** Using a while loop, create a list `numbers`{.docutils
    .literal .notranslate} that contains the numbers 0 through 35. Your
    while loop should initialize a counter variable to 0. On each
    iteration, the loop should append the current value of the counter
    to the list and the counter should increase by 1. The while loop
    should stop when the counter is greater than 35.
    :::
    :::
    :::
    :::

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

::: {#moreiter_ex_2 .full-width .container .question component="question" question_label="14.7.3"}
2.  ::: {.runestone .explainer .ac_section}
    ::: {#ac14_9_2 component="activecode" question_label="14.7.4"}
    ::: {#ac14_9_2_question .ac_question}
    Using a while loop, create a list called `L`{.docutils .literal
    .notranslate} that contains the numbers 0 to 10. (i.e.: Your while
    loop should initialize a counter variable to 0. On each iteration,
    the loop should append the current value of the counter variable to
    `L`{.docutils .literal .notranslate} and then increase the counter
    by 1. The while loop should stop once the counter variable is
    greater than 10.)
    :::
    :::
    :::
:::

::: {#moreiter_ex_3 .full-width .container .question component="question" question_label="14.7.5"}
3.  ::: {#q3 .alert .alert-warning component="tabbedStuff"}
    ::: {component="tab" tabname="Question"}
    ::: {.runestone .explainer .ac_section}
    ::: {#ac14_9_3 component="activecode" question_label="14.7.6"}
    ::: {#ac14_9_3_question .ac_question}
    Using a while loop, create a list called `nums`{.docutils .literal
    .notranslate} that contains the numbers 0 though 20. (i.e: your
    while looop should initialize a counter variable on 0. During each
    iteration, the loop should append the current value of the counter
    variable to `nums`{.docutils .literal .notranslate} and then
    increase the counter by 1. The while loop should stop once the
    counter variable is greater than 20)
    :::
    :::
    :::
    :::
    :::
:::

::: {#moreiter_ex_4 .full-width .container .question component="question" question_label="14.7.7"}
4.  ::: {.runestone .explainer .ac_section}
    ::: {#ac14_9_4 component="activecode" question_label="14.7.8"}
    ::: {#ac14_9_4_question .ac_question}
    Modify the walking turtle program so that rather than a 90 degree
    left or right turn the angle of the turn is determined randomly at
    each step.
    :::
    :::
    :::
:::

::: {#moreiter_ex_5 .full-width .container .question component="question" question_label="14.7.9"}
5.  ::: {#q5 .alert .alert-warning component="tabbedStuff"}
    ::: {component="tab" tabname="Question"}
    ::: {.runestone .explainer .ac_section}
    ::: {#ac14_9_5 component="activecode" question_label="14.7.10"}
    ::: {#ac14_9_5_question .ac_question}
    Modify the turtle walk program so that you have two turtles each
    with a random starting location. Keep the turtles moving until one
    of them leaves the screen.
    :::
    :::
    :::
    :::

    ::: {component="tab" tabname="Answer"}
    ::: {.runestone .explainer .ac_section}
    ::: {#q5_answer component="activecode" question_label="14.7.11"}
    ::: {#q5_answer_question .ac_question}
    :::
    :::
    :::
    :::

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

::: {#moreiter_ex_6 .full-width .container .question component="question" question_label="14.7.12"}
6.  ::: {.runestone .explainer .ac_section}
    ::: {#ac14_9_6 component="activecode" question_label="14.7.13"}
    ::: {#ac14_9_6_question .ac_question}
    Create a while loop that initializes a counter at 0 and will run
    until the counter reaches 50. If the value of the counter is
    divisible by 10, append the value to the list, `tens`{.docutils
    .literal .notranslate}.
    :::
    :::
    :::
:::

::: {#moreiter_ex_7 .full-width .container .question component="question" question_label="14.7.14"}
7.  ::: {.runestone .explainer .ac_section}
    ::: {#ac14_9_7 component="activecode" question_label="14.7.15"}
    ::: {#ac14_9_7_question .ac_question}
    Use a while loop to iterate through the numbers 0 through 35. If a
    number is divisible by 3, it should be appended to a list called
    `three_nums`{.docutils .literal .notranslate}.
    :::
    :::
    :::
:::

::: {#contributed-exercises .section}
[14.7.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"}
:::
:::

-   [[](WPInfiniteLoops.html)]{#relations-prev}
-   [[](ChapterAssessment.html)]{#relations-next}
:::

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

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