1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
diamong [38]
3 years ago
8

Define a function below, get_subset, which takes two arguments: a dictionary of strings (keys) to integers (values) and a list o

f strings. All of the strings in the list are keys to the dictionary. Complete the function such that it returns the subset of the dictionary defined by the keys in the list of strings. For example, with the dictionary {"puffin": 5, "corgi": 2, "three": 3} and the list ["three", "corgi"], your function should return {"corgi": 2, "three": 3}. Since dictionaries are unordered, you can add the keys to the new dictionary in any order.
Computers and Technology
1 answer:
frozen [14]3 years ago
3 0

Answer:

The following are the program in the Python Programming Language.

#define function

def get_subset(dic,lst):

   #declare dictionary type array

   res = {}

   #set the for loop

   for a in lst:

       #set the if conditional statement

       if a in dic:

           #assign the value of 'dic' in the 'res'

           res[a] = dic[a]

   #return the variable 'res'

   return res

Explanation:

<u>The following are description of the program</u>.

  • In the above program, define the function 'get_subset()' and pass two arguments in its parameter 'dic' and 'lst'.
  • Declare dictionary type variable 'res' then, set the for loop.
  • Then, set the if conditional statement that checks the elements of the variable 'a' in the variable 'dic' and assigns the value of 'dic' in the variable 'res'.
  • Finally, return the variable 'res'.
You might be interested in
I need help 40 points and brainless if you answer
Reil [10]
The answer is c
But I’m not sure
8 0
3 years ago
Read 2 more answers
Consider the following program. Assume all variables are declared and the program compiles.
Alexus [3.1K]
Hard question thx for the points give me brainlest points plz
8 0
3 years ago
Which of the follow is an example of an integer?<br> "1.091"<br> "number"<br> 15<br> name
UkoKoshka [18]

Answer:

The answer is 15

Explanation:

A integer is a whole number, the only wholenumber present is 15

Hope this helps :)

8 0
2 years ago
Write a program that asks for the number of calories and fat grams in a food. The program should display the percentage of calor
Zigmanuir [339]

Answer:

 The solution code is written in Python 3:

  1. calories = int(input("Enter number of calories: "))
  2. fats = int(input("Enter number of fat in grams: "))
  3. if(calories > 0 and fats > 0):
  4.    cf = fats * 9
  5.    if(cf < calories):
  6.        percent = cf / calories  
  7.        if(percent < 0.3):
  8.            print("Food is low in fat")
  9.    else:
  10.        print("Error input. Calories from fat cannot more than total calories")
  11. else:
  12.    print("Error input. Calories and fats must be more than 0")

Explanation:

Firstly, use input function to ask user to enter total number of calories and fat in grams (Line 1-2)

Next we do the first input validation to check if the calories and fats are more than 0 (Line 4). If so apply formula to calculate calories from fats. If not, print error input message (Line 5, 13)

Then we proceed to next input validation to check if calories from fact more than total calories. If so, proceed to calculate percentage of calories from fats and if it is lower than 30%, display the appropriate message (Line 6 - 9). If fail the second input validation, the program will display another error input message again (Line 11)

7 0
3 years ago
Suppose that TCP's current estimated values for the round trip time (estimatedRTT) and deviation in the RTT (DevRTT) are 400 mse
Masja [62]

Answer:

617.5 msecs, 580.89 msecs, 582.36 msecs

Explanation:

Lets look at the following formulas:

EstimatedRTT = α * SampleRTT+(1- α) * EstimatedRTT

DevRTT = β * | SampleRTT- EstimatedRTT|+(1- β)* DevRTT

TimeoutInterval = EstimatedRTT +4* DevRTT

Given values are:

EstimatedRTT = 400 msec

DevRTT = 25 msec

α = 0.125

β = 0.25

After the first RTT estimate: (210)

EstimatedRTT = 0.125 * 210 + (1 - 0.125) * 400 = 376.25 msecs

DevRTT = 0.25 * |210 - 376.25| + (1 - 0.25) * 25 = 60.3125 msecs

TimeoutInterval = 376.25 + 4 * 60.3125 = 617.5 msecs

After the second RTT estimate: (400)

EstimatedRTT = 0.125 * 400 + (1 - 0.125) * 376.25 = 379.218 msecs

DevRTT = 0.25 * |400 - 379.218| + (1 - 0.25) * 60.3125 = 50.42 msecs

TimeoutInterval = 379.218 + 4 * 50.42 = 580.89 msecs

After the third RTT estimate: (310)

EstimatedRTT = 0.125 * 310 + (1 - 0.125) * 379.218 = 370.56 msecs

DevRTT = 0.25 * |310 - 370.56| + (1 - 0.25) * 50.42 = 52.95 msecs

TimeoutInterval = 370.56 + 4 * 52.95 = 582.36 msecs

5 0
3 years ago
Other questions:
  • Jenny needs to record the names of 30 students, write down the subjects they studied, and note their grades in each subject afte
    8·2 answers
  • The equipment that processes data in order to create information is called the _______.
    8·2 answers
  • ___________ applications help you manage and present mathematical data easily and perfectly.
    14·1 answer
  • To use patterns and observations to say what happens next
    13·1 answer
  • Janice, who is 15, posts post a picture of herself drinking alcohol and making an obscene gesture on her social network page. wh
    15·2 answers
  • What shoul i get, Airpods or a ps4 cooling fan ???
    7·2 answers
  • How does the financial market impact the economy?
    10·1 answer
  • URLs are the global ______ of resources on the Internet.
    12·2 answers
  • Write an if-else statement for the following: If user_tickets is less than 5, assign 1 to num_tickets. Else, assign user_tickets
    6·1 answer
  • The following program is run. Then the user clicks the "bottomButton" TWO TIMES. What will be displayed in the console?
    6·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!