[Tutor] Alan G Week 10 warmup assignment help

Daniella Sapozhnikova daniellasapo at gmail.com
Fri Apr 1 21:21:02 EDT 2016


I changed the file to this:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Task 07: declaring a dictionary, creating a function,
return a funky total """


DATA = {2: 7493945,
        76: 4654320,
        3: 4091979,
        90: 1824881,
        82: 714422,
        45: 1137701,
        10: 374362,
        0: 326226,
        -15: 417203,
        -56: 333525,
        67: 323451,
        99: 321696,
        21: 336753,
        -100: 361237,
        55: 1209714,
        5150: 1771800,
        42: 4714011,
        888: 14817667,
        3500: 13760234,
        712: 10903322,
        7: 10443792,
        842: 11716264,
        18584: 10559923,
        666: 9275602,
        70: 11901200,
        153: 12074784,
        8: 4337229}


def iter_dict_funky_sum(data=DATA):
    """function that takes one dictionary argument declaring
    a running total variable, extracting key/value pairs from
    DATA simultaneously in a for loop, assigning and appending
    the product of the value minus the key to the running total
    variable and returning the total."""
    funky = 0
    for key, value in data.iteritems():
        funky += value - key
    return funky


however now pylint is returning:
task_07.py:36: [W0102(dangerous-default-value), iter_dict_funky_sum]
Dangerous default value DATA (__builtin__.dict) as argument

how can I pass the dictionary into the function, since pylint considers the
wway I'm doing it to be wrong?

the assignment specifications are:

#.  Create a file named ``task_07.py``

#.  Declare a variable named ``DATA`` as a dictionary object. Assign it a
set
    of key/value pairs. This is example data for you to work with but you
may
    create any dictionary of data provided it is at least 10 items long and
    both keys and values are integers.

#.  Create a function named ``iter_dict_funky_sum()`` that takes one
    dictionary argument.

    #.  Declare a running total integer variable.

    #.  Extract the key/value pairs from ``DATA`` simultaneously in a loop.
Do
        this with just one ``for`` loop and no additional forms of looping.

    #.  Assign and append the product of the value minus the key to the
running
        total variable.

    #.  Return the funky total.

I'm sure I'm doing everything else right, I guess pylint just doesn't like
how I'm declaring the variable? Everything is returning perfectly regarding
the example data and it's returning amount.

On Fri, Apr 1, 2016 at 12:00 PM, <tutor-request at python.org> wrote:

> Send Tutor mailing list submissions to
>         tutor at python.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
>         https://mail.python.org/mailman/listinfo/tutor
> or, via email, send a message with subject or body 'help' to
>         tutor-request at python.org
>
> You can reach the person managing the list at
>         tutor-owner at python.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Tutor digest..."
>
>
> Today's Topics:
>
>    1. Week 10 warmup assignment (Daniella Sapozhnikova)
>    2. Re: Week 10 warmup assignment (Alan Gauld)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Thu, 31 Mar 2016 23:26:38 -0400
> From: Daniella Sapozhnikova <daniellasapo at gmail.com>
> To: tutor at python.org
> Subject: [Tutor] Week 10 warmup assignment
> Message-ID:
>         <CAJs43K0sUYFcD4pe74yPowC4GWUVfii+0CoP=-
> jAC0b_d9ejPA at mail.gmail.com>
> Content-Type: text/plain; charset=UTF-8
>
> Umm I'm new to this whole tutoring list and I'm having a little bit of
> trouble in school with my programming classes (hopefully it's not too late
> to pass my class) but anyway, here's the code I've written:
>
>
> #!/usr/bin/env python
> # -*- coding: utf-8 -*-
> """Task 07: declaring a dictionary, creating a function,
> return a funky total """
>
>
> DATA = {2: 7493945,
>         76: 4654320,
>         3: 4091979,
>         90: 1824881,
>         82: 714422,
>         45: 1137701,
>         10: 374362,
>         0: 326226,
>         -15: 417203,
>         -56: 333525,
>         67: 323451,
>         99: 321696,
>         21: 336753,
>         -100: 361237,
>         55: 1209714,
>         5150: 1771800,
>         42: 4714011,
>         888: 14817667,
>         3500: 13760234,
>         712: 10903322,
>         7: 10443792,
>         842: 11716264,
>         18584: 10559923,
>         666: 9275602,
>         70: 11901200,
>         153: 12074784,
>         8: 4337229}
>
>
> def iter_dict_funky_sum(**DATA):
>     """function that takes one dictionary argument declaring
>     a running total variable, extracting key/value pairs from
>     DATA simultaneously in a for loop, assigning and appending
>     the product of the value minus the key to the running total
>     variable and returning the total."""
>     funky = 0
>     for key, value in DATA.iteritems():
>         funky += value - key
>     return funky
>
>
> Now, everything it's returning is correct, the only problems I'm having is
> the 2 errors pylint is throwing me, which are:
> task_07.py:36: [W0621(redefined-outer-name), iter_dict_funky_sum]
> Redefining name 'DATA' from outer scope (line 7)
> task_07.py:36: [C0103(invalid-name), iter_dict_funky_sum] Invalid argument
> name "DATA"
>
> What does it mean and how can I fix it?
>
>
> ------------------------------
>
> Message: 2
> Date: Fri, 1 Apr 2016 09:17:25 +0100
> From: Alan Gauld <alan.gauld at btinternet.com>
> To: tutor at python.org
> Subject: Re: [Tutor] Week 10 warmup assignment
> Message-ID: <ndlaql$bh1$1 at ger.gmane.org>
> Content-Type: text/plain; charset=utf-8
>
> On 01/04/16 04:26, Daniella Sapozhnikova wrote:
> > Umm I'm new to this whole tutoring list and I'm having a little bit of
> > trouble in school with my programming classes (hopefully it's not too
> late
> > to pass my class) but anyway, here's the code I've written:
> >
> >
> > #!/usr/bin/env python
> > # -*- coding: utf-8 -*-
> > """Task 07: declaring a dictionary, creating a function,
> > return a funky total """
> >
> >
> > DATA = {2: 7493945,
> >         76: 4654320,
> >         3: 4091979,
> >         90: 1824881,
> >         82: 714422,
> >         45: 1137701,
> >         10: 374362,
> >         0: 326226,
> >         -15: 417203,
> >         -56: 333525,
> >         67: 323451,
> >         99: 321696,
> >         21: 336753,
> >         -100: 361237,
> >         55: 1209714,
> >         5150: 1771800,
> >         42: 4714011,
> >         888: 14817667,
> >         3500: 13760234,
> >         712: 10903322,
> >         7: 10443792,
> >         842: 11716264,
> >         18584: 10559923,
> >         666: 9275602,
> >         70: 11901200,
> >         153: 12074784,
> >         8: 4337229}
> >
> >
> > def iter_dict_funky_sum(**DATA):
> >     """function that takes one dictionary argument declaring
> >     a running total variable, extracting key/value pairs from
> >     DATA simultaneously in a for loop, assigning and appending
> >     the product of the value minus the key to the running total
> >     variable and returning the total."""
> >     funky = 0
> >     for key, value in DATA.iteritems():
> >         funky += value - key
> >     return funky
> >
> >
> > Now, everything it's returning is correct, the only problems I'm having
> is
> > the 2 errors pylint is throwing me, which are:
> > task_07.py:36: [W0621(redefined-outer-name), iter_dict_funky_sum]
> > Redefining name 'DATA' from outer scope (line 7)
> > task_07.py:36: [C0103(invalid-name), iter_dict_funky_sum] Invalid
> argument
> > name "DATA"
> >
> > What does it mean and how can I fix it?
>
>
> It means you have the same name for your parameter as for your global
> variable which is potentially confusing, so change the name of your
> parameter.
>
> Also you don't need the ** in front of DATA in the function definition.
>
> Finally, you say it's working but you don't actually call your
> function in your code. How are you exercising it? Did you just miss that
> bit out or are you importing at the  >>> prompt?
>
> --
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
> http://www.amazon.com/author/alan_gauld
> Follow my photo-blog on Flickr at:
> http://www.flickr.com/photos/alangauldphotos
>
>
>
>
> ------------------------------
>
> Subject: Digest Footer
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> https://mail.python.org/mailman/listinfo/tutor
>
>
> ------------------------------
>
> End of Tutor Digest, Vol 146, Issue 1
> *************************************
>


More information about the Tutor mailing list