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
Firdavs [7]
2 years ago
15

The add_prices function returns the total price of all of the groceries in the dictionary. Fill in the blanks to complete this f

unction (python):def add_prices(basket): # Initialize the variable that will be used for thecalculation total = 0 # Iterate through the dictionary items for ___: # Add each price to the totalcalculation # Hint: how do you access thevalues of # dictionary items? total += ___ # Limit the return value to 2 decimal places return round(total, 2)groceries = {"bananas": 1.56, "apples": 2.50, "oranges": 0.99,"bread": 4.59, "coffee": 6.99, "milk": 3.39, "eggs": 2.98, "cheese":5.44}print(add_prices(groceries)) # Should print 28.44
Computers and Technology
1 answer:
Vlada [557]2 years ago
8 0

Answer:

def add_prices(basket):

 

   total = 0

   for items in basket.values():

       total += items

   return round(total, 2)

groceries = {"bananas": 1.56, "apples": 2.50, "oranges": 0.99,"bread": 4.59, "coffee": 6.99, "milk": 3.39, "eggs": 2.98, "cheese":5.44}

print(add_prices(groceries)) # Should print 28.44

Explanation:

The python dictionary is a data structure that stores items of data as a key-value pair. The keys and values can be listed separately using the keys() and values() built-in function.

The program above uses a for loop statement to iterate over the values of the groceries dictionary to return the total sum of the values.

You might be interested in
A painting company has determined that for every 115 square feet or wall space, one gallon of paint and eight hours of labor wil
Kay [80]

The program to calculate the total paint cost and other values is given below.

#include <iostream>

using namespace std;

int main() {  

 int rooms, laborChrg = 18;

 float paintChrg;

 float feetPerRoom[rooms];  

 float paintReq, laborHrs, paintCost, laborCost, totalCost, totalsqft=0;  

 cout<<"Enter the number of rooms to be painted "<<endl;

 cin>>rooms;  

 for(int i=0; i <= rooms; i++)

 {

 cout<<"Enter the square feet in room "<<endl;

 cin>>feetPerRoom[i];  

 // shortcut operator which is equivalent to totalsqft = totalsqft +     feetPerRoom[i];

 totalsqft += feetPerRoom[i];

 }  

 cout<<"Enter the cost of the paint per gallon "<<endl;

 cin>>paintChrg;  

 laborHrs = (totalsqft/115)*8;

 laborCost = laborHrs * laborChrg;  

 paintReq = totalsqft/115;

 paintCost = paintReq * paintChrg;  

 totalCost = laborCost + paintCost;  

 cout<<"The number of gallons of paint required "<<paintReq<<endl;

 cout<<"The hours of labor required "<<laborHrs<<endl;

 cout<<"The cost of the paint is "<<paintCost<<endl;

 cout<<"The labor charges are "<<laborHrs<<endl;

 cout<<"The Total cost of the paint job is "<<totalCost<<endl;  

 return 0;

}

Explanation:

The header files for input and output are imported.

#include <iostream>

using namespace std;

All the variables are taken as float except labour charge per hour and number of rooms.

The user is asked to input the number of rooms to be painted. An array holds the square feet in each room to be painted.

cout<<"Enter the number of rooms to be painted "<<endl;

cin>>rooms;  

for(int i=0; i <= rooms; i++)

{

cout<<"Enter the square feet in room "<<endl;

cin>>feetPerRoom[i];  

totalsqft += feetPerRoom[i];

}  

The above code asks for square feet in each room and calculates the total square feet to be painted simultaneously.

All the data to be displayed is calculated based on the values of labor charge per hour and gallons of paint needed, given in the question.

laborHrs = (totalsqft/115)*8;

laborCost = laborHrs * laborChrg;

paintReq = totalsqft/115;

paintCost = paintReq * paintChrg;

totalCost = laborCost + paintCost;

All the calculated values are displayed in the mentioned order.

7 0
3 years ago
How does technology improve productivity at home? (Select all that apply.)
Aliun [14]

Answer:

B, C

Explanation:

?

5 0
3 years ago
What is machine level language ?​
NeX [460]

Answer:

The machine-level language is a language that consists of a set of instructions that are in the binary form 0 or 1.

5 0
2 years ago
How could this<br> innovation change society?
Lisa [10]

Answer:

invention such as new tool devices progress and resistance benefits to society inventions selfie lies and provide new way to build move communicate heal learn and play

7 0
2 years ago
Homework 8 Matlab Write a function called fibonacciMatrix. It should have three inputs, col1, col2, and n. col1 and col2 are ver
Amiraneli [1.4K]

In this exercise we have to use the knowledge in computational language in python to write the following code:

We have the code can be found in the attached image.

So in an easier way we have that the code is:

<em>function v = myfib(n,v)</em>

<em>if nargin==1</em>

<em>    v = myfib(n-1,[0,1]);</em>

<em>elseif n>1</em>

<em>    v = myfib(n-1,[v,v(end-1)+v(end)]);</em>

<em>end</em>

<em>end</em>

<em>function v = myfib(n,v)</em>

<em>if nargin==1</em>

<em>    v = myfib(n-1,[0,1]);</em>

<em>elseif n>1</em>

<em>    v = myfib(n-1,[v,v(end-1)+v(end)]);</em>

<em>elseif n<1</em>

<em>    v = 0;</em>

<em>end</em>

<em>function [n] = abcd(x)</em>

<em>if (x == 1 || x==0)</em>

<em>    n = x; </em>

<em>    return</em>

<em>else</em>

<em>    n = abcd(x-1) + abcd(x-2);</em>

<em>end</em>

<em>end</em>

<em>fibonacci = [0 1];</em>

<em>for i = 1:n-2</em>

<em>    fibonacci = [fibonacci fibonacci(end)+fibonacci(end-1)];</em>

<em>end</em>

<em>>> myfib(8)</em>

<em>ans =</em>

<em>    0    1    1    2    3    5    8   13</em>

<em>>> myfib(10)</em>

<em>ans =</em>

<em>    0    1    1    2    3    5    8   13   21   34</em>

See more about python at  brainly.com/question/18502436

8 0
1 year ago
Other questions:
  • ANSWER IN 5 MINUTES TO GET 50 POINTS!!!
    13·1 answer
  • You disassemble and reassemble a desktop computer. when you first turn it on, you see no lights and hear no sounds. nothing appe
    11·2 answers
  • When using the boolean data type, we encapsulate the data in what symbol?
    11·2 answers
  • The 2 main types of copyright relevant to the recording industry?
    5·2 answers
  • How should font appear in a slide presentation compared to the font in a document
    7·1 answer
  • This is in government
    15·1 answer
  • How many answers do you need to be able to write messages on here??
    6·1 answer
  • Which SCSI standard allows for the technique known as “hot swapping”? Ultra SCSI Original SCSI Serial SCSI Fast-Wide SCSI
    5·1 answer
  • Explain the paging concept and main disadvantages of pipelined
    15·1 answer
  • It is possible to create a share that is invisible to users browsing the network simply by appending what character to the end o
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!