Question

In: Computer Science

Python HW with Jupyter Notebook Declare a variable named DATA as a dictionary object. Assign the...

Python HW with Jupyter Notebook

  1. Declare a variable named DATA as a dictionary object. Assign the set of key/value pairs shown below.
  2. Create a function named iter_dict_funky_sum() that takes one dictionary argument.   
  3. Declare a running total integer variable.
  4. Extract the key/value pairs from DATA simultaneously in a loop. Do this with just one for loop and no additional forms of looping.
  5. Assign and append the product of the value minus the key to the running total variable.
  6. 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

Solutions

Expert Solution

Code:

# d is the input dictionary
def iter_dict_funky_sum(d):
  total = 0
  for key,value in d.items(): # iterate through dictionary in a single loop
    total = total + (value - key) # append to total value - key
  return total # return 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
}
iter_dict_funky_sum(DATA)

code screenshot:

===========

Code alongs with comment and screenshot has been added.


Related Solutions

Python HW Open a new Jupyter notebook Create a new function named fibonacci() that takes one...
Python HW Open a new Jupyter notebook Create a new function named fibonacci() that takes one required parameter: maxint, an integer that will serve as the upper bound of the loop Following the example on the Python tutorial: https://docs.python.org/3/tutorial/introduction.html#first-steps-towards-programming Our implementation will have a few changes: While you will use a while loop to make a Fibonacci sequence, the upper bound of the sequence will be your maxint parameter. Store the results into a list and append each new generated...
The purpose of this is to plot data using Matplotlib. Description complete the Jupyter notebook named...
The purpose of this is to plot data using Matplotlib. Description complete the Jupyter notebook named main.ipynb that reads in the file diamonds.csv into a Pandas DataFrame. Information about the file can be found here: ------- diamonds R Documentation Prices of over 50,000 round cut diamonds Description A dataset containing the prices and other attributes of almost 54,000 diamonds. The variables are as follows: Usage diamonds Format A data frame with 53940 rows and 10 variables: price price in US...
Create a new Python 3 Jupyter Notebook. At the top, be sure to name your notebook...
Create a new Python 3 Jupyter Notebook. At the top, be sure to name your notebook as "*assignment 2.08 - Your Name Here.ipynb*" (obviously, replace the "Your Name Here" part with your actual name). Create a single python cell to program the following specifications. Use what you've learned on this page to: 1. Find the index of "lmno" in the English alphabet using an appropriate instruction and store it in a variable. (hint: you'll need to define a string that...
Please give me an example of how we import stock data in jupyter notebook(Python) and analyze...
Please give me an example of how we import stock data in jupyter notebook(Python) and analyze each step.
Focuses on the design, development, implementation, and testing of a Python program using Jupyter Notebook only...
Focuses on the design, development, implementation, and testing of a Python program using Jupyter Notebook only to solve the problem described below. You will write a program that simulates an Automatic Teller Machine (ATM). For this program, your code can have of user-defined functions only. However, the program must not call on any external functions or modules to handle any of the input, computational, and output requirements. Note, the program can be completed without the use of user-defined functions. Requirements:...
Python: Using Jupyter Notebook 1. Write code to generate Fibonacci series. Fibonacci numbers – 1, 1,...
Python: Using Jupyter Notebook 1. Write code to generate Fibonacci series. Fibonacci numbers – 1, 1, 2, 3, 5, 8, … 2. Check if a number is an Armstrong number A positive integer is called an Armstrong number of order n if abcd... = a^n + b^n + c^n + d^n + ... In case of an Armstrong number of 3 digits, the sum of cubes of each digits is equal to the number itself. For example: 153 = 1*1*1...
Machine Learning do using python on jupyter notebook 1. Linear Regression Dataset used: Diabetes from sklearn...
Machine Learning do using python on jupyter notebook 1. Linear Regression Dataset used: Diabetes from sklearn You are asked to solve a regression problem in the Diabetes dataset. Please review the Diabetes dataset used before creating a program to decide which attributes will be used in the regression process. please use the cross-validation step to produce the best evaluation of the model. All you have to do is • Perform linear regression using the OLS (Ordinary Least Square) method (sklearn.linear_model.LinearRegression)...
What is the python code to solve this type of nonlinear equation in jupyter notebook 16cos2x+16sin2x-40.1cosx+2.3sinx+16.223=0...
What is the python code to solve this type of nonlinear equation in jupyter notebook 16cos2x+16sin2x-40.1cosx+2.3sinx+16.223=0 Please show the code clearly.
Problem: Perform the word counter problem through MapReduce. Tools: Anaconda/Python 3/Jupyter Notebook Example word: “One a...
Problem: Perform the word counter problem through MapReduce. Tools: Anaconda/Python 3/Jupyter Notebook Example word: “One a penny, two a penny, hot cross buns.” Submitted files: (1) Source code (adding comments); (2) Supporting document for code comments
In Java form Declare and assign a char variable called myLetter to z. Write a Java...
In Java form Declare and assign a char variable called myLetter to z. Write a Java statement that makes myLetter uppercase. Write a java statement that finds out if myLetter is a digit. Write a java statement that finds out if myLetter is an upper case letter. Assume myLetter = ‘Z’; What is the output for System.out.print(myLetter++); Assume myLetter = ‘Z’; What is the output for System.out.print(++myLetter); Assume myLetter = ‘Z’; What is the output for System.out.print(myLetter--); What happens when...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT