What i wrong with my code

0 votes

Specifications

  1. Use a new cell in your notebook
  2. Declare a variable named DATA as a dictionary object. Assign the set of key/value pairs shown below.
  3. Create a function named iter_dict_funky_sum() that takes one dictionary argument.
    1. Declare a running total integer variable.
    2. Extract the key/value pairs from DATA simultaneously in a loop. Do this with just one for loop and no additional forms of looping.
    3. Assign and append the product of the value minus the key to the running total variable.
    4. Return the funky total.

Dictionary Data

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
}

Expected Output

>>> iter_dict_funky_sum(DATA)
140166242


here is the code I wrote

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(dictionary):
    running = 0
    for key,value in dictionary.iteritems():
    running+=(value-key)
      return running 
print(iter_dict_funky_sum(DATA))

    

Mar 20, 2022 in Python by Liubov

edited 5 days ago 8 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP