::: {#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}
    -   [12.1 Introduction to
        Functions](intro-Functions.html){.reference .internal}
    -   [12.2 Function Definition](FunctionDefinitions.html){.reference
        .internal}
    -   [12.3 Function Invocation](FunctionInvocation.html){.reference
        .internal}
    -   [12.4 Function Parameters](FunctionParameters.html){.reference
        .internal}
    -   [12.5 Returning a value from a
        function](Returningavaluefromafunction.html){.reference
        .internal}
    -   [12.6 👩‍💻 Decoding a
        Function](DecodingaFunction.html){.reference .internal}
    -   [12.7 Type Annotations](TypeAnnotations.html){.reference
        .internal}
    -   [12.8 A function that
        accumulates](Afunctionthataccumulates.html){.reference
        .internal}
    -   [12.9 Variables and parameters are
        local](Variablesandparametersarelocal.html){.reference
        .internal}
    -   [12.10 Global Variables](GlobalVariables.html){.reference
        .internal}
    -   [12.11 Functions can call other functions
        (Composition)](Functionscancallotherfunctions.html){.reference
        .internal}
    -   [12.12 Flow of Execution
        Summary](FlowofExecutionSummary.html){.reference .internal}
    -   [12.13 👩‍💻 Print vs. return](Printvsreturn.html){.reference
        .internal}
    -   [12.14 Passing Mutable
        Objects](PassingMutableObjects.html){.reference .internal}
    -   [12.15 Side Effects](SideEffects.html){.reference .internal}
    -   [12.16 Glossary](Glossary.html){.reference .internal}
    -   [12.17 Exercises](Exercises.html){.reference .internal}
    -   [12.18 Chapter Assessment](ChapterAssessment.html){.reference
        .internal}
-   
-   
:::
:::
:::

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

::: {#main-content .container role="main"}
::: {#exercises .section}
[12.17. ]{.section-number}Exercises[¶](#exercises "Permalink to this heading"){.headerlink}
===========================================================================================

1.  ::: {#q1 .alert .alert-warning component="tabbedStuff"}
    ::: {component="tab" tabname="Question"}
    ::: {.runestone .explainer .ac_section}
    ::: {#ac11_14_1 component="activecode" question_label="12.17.1"}
    ::: {#ac11_14_1_question .ac_question}
    Write a function named `num_test`{.docutils .literal .notranslate}
    that takes a number as input. If the number is greater than 10, the
    function should return "Greater than 10." If the number is less than
    10, the function should return "Less than 10." If the number is
    equal to 10, the function should return "Equal to 10."
    :::
    :::
    :::
    :::
    :::

2.  ::: {#q2 .alert .alert-warning component="tabbedStuff"}
    ::: {component="tab" tabname="Question"}
    ::: {.runestone .explainer .ac_section}
    ::: {#ac11_14_2 component="activecode" question_label="12.17.2"}
    ::: {#ac11_14_2_question .ac_question}
    Write a function that will return the number of digits in an
    integer.
    :::
    :::
    :::
    :::

    ::: {component="tab" tabname="Answer"}
    ::: {.runestone .explainer .ac_section}
    ::: {#answer11_14_2 component="activecode" question_label="12.17.3"}
    ::: {#answer11_14_2_question .ac_question}
    :::
    :::
    :::
    :::

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

3.  ::: {#q3 .alert .alert-warning component="tabbedStuff"}
    ::: {component="tab" tabname="Question"}
    ::: {.runestone .explainer .ac_section}
    ::: {#ac11_14_3 component="activecode" question_label="12.17.4"}
    ::: {#ac11_14_3_question .ac_question}
    Write a function that reverses its string argument.
    :::
    :::
    :::
    :::
    :::

4.  ::: {#q4 .alert .alert-warning component="tabbedStuff"}
    ::: {component="tab" tabname="Question"}
    ::: {.runestone .explainer .ac_section}
    ::: {#ac11_14_4 component="activecode" question_label="12.17.5"}
    ::: {#ac11_14_4_question .ac_question}
    Write a function that mirrors its string argument, generating a
    string containing the original string and the string backwards.
    :::
    :::
    :::
    :::

    ::: {component="tab" tabname="Answer"}
    ::: {.runestone .explainer .ac_section}
    ::: {#answer11_14_4 component="activecode" question_label="12.17.6"}
    ::: {#answer11_14_4_question .ac_question}
    :::
    :::
    :::
    :::

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

5.  ::: {#q5 .alert .alert-warning component="tabbedStuff"}
    ::: {component="tab" tabname="Question"}
    ::: {.runestone .explainer .ac_section}
    ::: {#ac11_14_5 component="activecode" question_label="12.17.7"}
    ::: {#ac11_14_5_question .ac_question}
    Write a function that removes all occurrences of a given letter from
    a string.
    :::
    :::
    :::
    :::
    :::

6.  ::: {#q6 .alert .alert-warning component="tabbedStuff"}
    ::: {component="tab" tabname="Question"}
    ::: {.runestone .explainer .ac_section}
    ::: {#ac11_14_6 component="activecode" question_label="12.17.8"}
    ::: {#ac11_14_6_question .ac_question}
    Although Python provides us with many list methods, it is good
    practice and very instructive to think about how they are
    implemented. Implement a Python function that works like the
    following:

    1.  count

    2.  in

    3.  reverse

    4.  index

    5.  insert
    :::
    :::
    :::
    :::

    ::: {component="tab" tabname="Answer"}
    ::: {.runestone .explainer .ac_section}
    ::: {#answer11_14_6 component="activecode" question_label="12.17.9"}
    ::: {#answer11_14_6_question .ac_question}
    :::
    :::
    :::
    :::

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

7.  ::: {#q7 .alert .alert-warning component="tabbedStuff"}
    ::: {component="tab" tabname="Question"}
    ::: {.runestone .explainer .ac_section}
    ::: {#ac11_14_7 component="activecode" question_label="12.17.10"}
    ::: {#ac11_14_7_question .ac_question}
    Write a function `replace(s, old, new)`{.docutils .literal
    .notranslate} that replaces all occurences of `old`{.docutils
    .literal .notranslate} with `new`{.docutils .literal .notranslate}
    in a string `s`{.docutils .literal .notranslate}:

    ::: {.highlight-default .notranslate}
    ::: {.highlight}
        test(replace('Mississippi', 'i', 'I'), 'MIssIssIppI')

        s = 'I love spom!  Spom is my favorite food.  Spom, spom, spom, yum!'
        test(replace(s, 'om', 'am'),
               'I love spam!  Spam is my favorite food.  Spam, spam, spam, yum!')

        test(replace(s, 'o', 'a'),
               'I lave spam!  Spam is my favarite faad.  Spam, spam, spam, yum!')
    :::
    :::

    *Hint*: use the `split`{.docutils .literal .notranslate} and
    `join`{.docutils .literal .notranslate} methods.
    :::
    :::
    :::
    :::
    :::

8.  ::: {#q8 .alert .alert-warning component="tabbedStuff"}
    ::: {component="tab" tabname="Question"}
    ::: {.runestone .explainer .ac_section}
    ::: {#ac11_14_8 component="activecode" question_label="12.17.11"}
    ::: {#ac11_14_8_question .ac_question}
    Write a Python function that will take a the list of 100 random
    integers between 0 and 1000 and return the maximum value. (Note:
    there is a builtin function named `max`{.docutils .literal
    .notranslate} but pretend you cannot use it.)
    :::
    :::
    :::
    :::

    ::: {component="tab" tabname="Answer"}
    ::: {.runestone .explainer .ac_section}
    ::: {#answer11_14_8 component="activecode" question_label="12.17.12"}
    ::: {#answer11_14_8_question .ac_question}
    :::
    :::
    :::
    :::

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

9.  ::: {#q9 .alert .alert-warning component="tabbedStuff"}
    ::: {component="tab" tabname="Question"}
    ::: {.runestone .explainer .ac_section}
    ::: {#ac11_14_9 component="activecode" question_label="12.17.13"}
    ::: {#ac11_14_9_question .ac_question}
    Write a function `sum_of_squares(xs)`{.docutils .literal
    .notranslate} that computes the sum of the squares of the numbers in
    the list `xs`{.docutils .literal .notranslate}. For example,
    `sum_of_squares([2, 3, 4])`{.docutils .literal .notranslate} should
    return 4+9+16 which is 29:
    :::
    :::
    :::
    :::
    :::

10. ::: {#q10 .alert .alert-warning component="tabbedStuff"}
    ::: {component="tab" tabname="Question"}
    ::: {.runestone .explainer .ac_section}
    ::: {#ac11_14_10 component="activecode" question_label="12.17.14"}
    ::: {#ac11_14_10_question .ac_question}
    Write a function to count how many odd numbers are in a list.
    :::
    :::
    :::
    :::

    ::: {component="tab" tabname="Answer"}
    ::: {.runestone .explainer .ac_section}
    ::: {#answer11_14_10 component="activecode" question_label="12.17.15"}
    ::: {#answer11_14_10_question .ac_question}
    :::
    :::
    :::
    :::

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

11. ::: {#q11 .alert .alert-warning component="tabbedStuff"}
    ::: {component="tab" tabname="Question"}
    ::: {.runestone .explainer .ac_section}
    ::: {#ac11_14_11 component="activecode" question_label="12.17.16"}
    ::: {#ac11_14_11_question .ac_question}
    Sum up all the even numbers in a list.
    :::
    :::
    :::
    :::
    :::

12. ::: {#q12 .alert .alert-warning component="tabbedStuff"}
    ::: {component="tab" tabname="Question"}
    ::: {.runestone .explainer .ac_section}
    ::: {#ac11_14_12 component="activecode" question_label="12.17.17"}
    ::: {#ac11_14_12_question .ac_question}
    Sum up all the negative numbers in a list.
    :::
    :::
    :::
    :::

    ::: {component="tab" tabname="Answer"}
    ::: {.runestone .explainer .ac_section}
    ::: {#answer11_14_12 component="activecode" question_label="12.17.18"}
    ::: {#answer11_14_12_question .ac_question}
    :::
    :::
    :::
    :::

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

13. ::: {#q13 .alert .alert-warning component="tabbedStuff"}
    ::: {component="tab" tabname="Question"}
    ::: {.runestone .explainer .ac_section}
    ::: {#ac11_14_13 component="activecode" question_label="12.17.19"}
    ::: {#ac11_14_13_question .ac_question}
    Write a function `findHypot`{.docutils .literal .notranslate}. The
    function will be given the length of two sides of a right-angled
    triangle and it should return the length of the hypotenuse. (Hint:
    `x ** 0.5`{.docutils .literal .notranslate} will return the square
    root, or use `sqrt`{.docutils .literal .notranslate} from the math
    module)
    :::
    :::
    :::
    :::
    :::

14. ::: {#q14 .alert .alert-warning component="tabbedStuff"}
    ::: {component="tab" tabname="Question"}
    ::: {.runestone .explainer .ac_section}
    ::: {#ac11_14_14 component="activecode" question_label="12.17.20"}
    ::: {#ac11_14_14_question .ac_question}
    Write a function called `is_even(n)`{.docutils .literal
    .notranslate} that takes an integer as an argument and returns
    `True`{.docutils .literal .notranslate} if the argument is an **even
    number** and `False`{.docutils .literal .notranslate} if it is
    **odd**.
    :::
    :::
    :::
    :::
    :::

15. ::: {#q15 .alert .alert-warning component="tabbedStuff"}
    ::: {component="tab" tabname="Question"}
    ::: {.runestone .explainer .ac_section}
    ::: {#ac11_14_15 component="activecode" question_label="12.17.21"}
    ::: {#ac11_14_15_question .ac_question}
    Now write the function `is_odd(n)`{.docutils .literal .notranslate}
    that returns `True`{.docutils .literal .notranslate} when
    `n`{.docutils .literal .notranslate} is odd and `False`{.docutils
    .literal .notranslate} otherwise.
    :::
    :::
    :::
    :::
    :::

16. ::: {#q16 .alert .alert-warning component="tabbedStuff"}
    ::: {component="tab" tabname="Question"}
    ::: {.runestone .explainer .ac_section}
    ::: {#ac11_14_16 component="activecode" question_label="12.17.22"}
    ::: {#ac11_14_16_question .ac_question}
    Write a function `is_rightangled`{.docutils .literal .notranslate}
    which, given the length of three sides of a triangle, will determine
    whether the triangle is right-angled. Assume that the third argument
    to the function is always the longest side. It will return
    `True`{.docutils .literal .notranslate} if the triangle is
    right-angled, or `False`{.docutils .literal .notranslate} otherwise.

    Hint: floating point arithmetic is not always exactly accurate, so
    it is not safe to test floating point numbers for equality. If a
    good programmer wants to know whether `x`{.docutils .literal
    .notranslate} is equal or close enough to `y`{.docutils .literal
    .notranslate}, they would probably code it up as

    ::: {.highlight-python .notranslate}
    ::: {.highlight}
        if  abs(x - y) < 0.001:      # if x is approximately equal to y
            ...
    :::
    :::
    :::
    :::
    :::
    :::
    :::

::: {#contributed-exercises .section}
[12.17.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}
-   [[](ChapterAssessment.html)]{#relations-next}
:::

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

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