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
Margaret [11]
2 years ago
7

Create a two functions: first called grocery_cost(food), where food can be one item or a list of items from the stock and price

dictionaries, the second is called stock_check(stock_list) where a store manager can check if stock numbers are at a minimum value.grocery_cost: loops through the argument food, notes the price, checks the stock, calculates and prints the total cost and changes the stock number. You will need to use a for statement to loop through the items in food and an if statement to check and update the stock (substract one from the stock for each item in the stock).Stock_check: loops through each item in the stock dictionary and uses an if-statement to print a statement if stock is less than 5.Given:stock_key={'tomato soup':20,'cheese':10,'milk':25,'oreos':100,'red bull':0,'apples':17,'oranges':4}price_key={'tomato soup':1.85,'cheese':3.99,'milk':4,'oreos':7.49,'red bull':0.99,'apples':0.59,'oranges':1.29}
Computers and Technology
1 answer:
Elena L [17]2 years ago
6 0

Answer:

stock_key={'tomato soup':20,'cheese':10,'milk':25,'oreos':100,'red bull':0,'apples':17,'oranges':4}

price_key={'tomato soup':1.85,'cheese':3.99,'milk':4,'oreos':7.49,'red bull':0.99,'apples':0.59,'oranges':1.29}

def grocery_cost(*args):

   total_cost = 0

   for arg in args:

       if arg in stock_key.keys():

           stock_key[arg] -= 1

           total_cost += price_key[arg]

   print( f"Total cost of groceries: {total_cost}")

def stock_check():

   for key, value in stock_key.items():

       if value < 5:

          print(f"The stock \"{key}\" is less than 5.")

grocery_cost('apples', 'oranges','milk', 'oreos','cheese')

stock_check()

Explanation:

The functions of grocery_cost and stock_check are python defined functions. The former accepts a list of one or more items and calculates the total cost of the grocery items from the stock and price dictionary while the latter check the size of the stock in the food store.

You might be interested in
Write a program that asks the user to enter the amount s/he has budgeted for a month. The amount should be between 1000 and 2000
Elena-2011 [213]

Answer:

The program to this question can be given as:

Program:

  //import package for user input.

import java.util.*;      

//define class

public class Budget                      

{

public static void main(String [] a)            //define main method.

{

//creating Scanner class object.

Scanner ob =new Scanner(System.in);    

//define variable.      

double budgetamount=0, amountspent=0 ,difference=0,total=0,num=0 ;        

int count = 0;                            

System.out.println("How much have you budgeted for the month? :");        //print message.

budgetamount=ob.nextDouble();                             //taking input

       while(budgetamount != 0)           //checkig number greater then 4 digite.

       {

           budgetamount= budgetamount/10;        

           ++count;

       }

       if(count>4)                 //condition

       {

       System.out.println("enter each expense, then type -999 to quit: ");

       while(num!=-999)               //taking expense  

       {

       total=total+num;                 //totaling expense

       num=scan.nextDouble();                  

       }

       if(total<=budgetamount)           //condtion for over budget.

       {

       System.out.print("under budget:");         //print message

       System.out.print(budgetamount-total);

       }

       else

       {

       System.out.print("over budget:");              //for under budget

       System.out.print(total-budgetamount);

       }

       }

       else

       {

       System.out.println("not valid");        //message for number lessthen 4 digit.    

       }                                      

}

}

output:

How much have you budgeted for the month? : 1200.55.

enter each expense, then type -999 to quit: 365.89

556.90

339.98

-999

over budget:1262.77

Explanation:

The explanation of this program can be given as:

In the above program we import the package in that is used for scanner class. This class is used for the input from the user after input we use the while loop and if-else statement. The while loop is the entry control loop It is used for input validation and if-else is used for the checking condition. Then we insert expense that is inserted by the user. Then we calculate under-budgeted and over-budgeted by conditional statement that is if-else. and at the last we print it.

5 0
3 years ago
What is the most important for you to choose before you build a network?
olga nikolaevna [1]
Network media is most important
4 0
3 years ago
Which property is assigned to a file by the operating system?
Zolol [24]
Your answer would be a type
7 0
3 years ago
________ is digital textual information that can be stored, manipulated, and transmitted by electronic devices.
mars1129 [50]
E-text <span>is digital textual information that can be stored, manipulated, and transmitted by electronic devices. The term "e-text" stands for electronic text and it is used for any digital document written, read, transmitted or manipulated by electronic devices, such as smart phones, PCs, tablets,...The origins of the e-text are in the beginning of the Internet.</span>
7 0
3 years ago
Which of the following is a precaution that helps to protect you from electric shock when working with electric power tools?
olga2289 [7]
A A is the best answer to this question.
5 0
3 years ago
Read 2 more answers
Other questions:
  • It proceeds the statement causes execution of the current loop iteration to end and commence at the beginning of the next loop.
    10·1 answer
  • How did mark watney survive the accident
    9·1 answer
  • jason works for a restaurant that serves only organic local produced what trend is this business following?
    6·2 answers
  • If Tracy starts on the left edge of the canvas and moves forward 50 pixels, how many times will this code need to be repeated to
    5·1 answer
  • The CSS property of top , bottom , left , or right moves the element the specified distance from the respective edge of the clos
    7·1 answer
  • You dad has given you his old digital scanner for your new computer. you plug it into the usb drive on your windows 8 computer b
    8·1 answer
  • The use of desktop computer equipment and software to create high-quality documents such as newsletters, business cards, letterh
    14·1 answer
  • Briefly describe the traditional definition of the digital divide. What is it and who is affected, positively and adversely? How
    15·1 answer
  • Question is in photo
    11·1 answer
  • In which drawer do you find blocks that allow you to use the A and B buttons on your micro:bit?
    13·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!