[Tutor] week 10 warm up assignment
Daniella Sapozhnikova
daniellasapo at gmail.com
Fri Apr 1 22:19:49 EDT 2016
I tried changing the file earlier, however it wasn't returning the
apropriate value, so the file looks the same as earlier:
#!/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
the assignment specifications include:
#. 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.
and pylint is throwing these errors:
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"
my question is: how would i go about passing the dictionary into the
function without pylint throwing errors? Basically how would I pass a
dictionary to a function (am I doing it right???)
Thank you,
Daniella Sapozhnikova
More information about the Tutor
mailing list