[Tutor] Week 10 warmup assignment

Alan Gauld alan.gauld at btinternet.com
Fri Apr 1 04:17:25 EDT 2016


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




More information about the Tutor mailing list