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
evablogger [386]
4 years ago
6

Fill in the function shopSmart(orders,shops) in shopSmart.py, which takes an orderList (like the kind passed in to FruitShop.get

PriceOfOrder) and a list of FruitShop and returns the FruitShop where your order costs the least amount in total. Don't change the file name or variable names, please. Note that we will provide the shop.py implementation as a "support" file, so you don't need to submit yours. Run python autograder.py until question 3 passes all tests and you get full marks. Each test will confirm that shopSmart(orders,shops) returns the correct answer given various possible inputs. For example, with the following variable definitions: orders1 = [('apples',1.0), ('oranges',3.0)] orders2 = [('apples',3.0)] dir1 = {'apples': 2.0, 'oranges':1.0} shop1 = shop.FruitShop('shop1',dir1) dir2 = {'apples': 1.0, 'oranges': 5.0} shop2 = shop.FruitShop('shop2',dir2) shops = [shop1, shop2] test_cases/q3/select_shop1.test tests whether:

Computers and Technology
1 answer:
ira [324]4 years ago
8 0

Answer:

def shopSmart(orderList, fruitShops):  #function definition

   shop = fruitShops[0] #sets the shop to first item of fruitShops list

   leastAmount = shop.getPriceOfOrder(orderList)  #passes the orderList to getPriceOfOrder method which returns the total cost and saves it to leastAmount

   for fruitshop in fruitShops[1:]:  #iterates through the shops in fruitShops list

    cost = fruitshop.getPriceOfOrder(orderList)  #checks each cost or order using getPriceOfOrder method and passing orderList to it

    if cost < leastAmount:  #checks where order costs the least amount in total

     shop = fruitshop  #sets the FruitShop where order costs the least amount in total

     leastAmount = cost  #sets that minimum of order cost to leastAmount

   return shop #returns the FruitShop where order costs the least amount in total

Explanation:

Here are the getPriceOfOrder() and getName()) methods that is used in the above method.

def getPriceOfOrder(self, orderList):        

       totalCost = 0.0              

       for fruit, numPounds in orderList:

           costPerPound = self.getCostPerPound(fruit)

           if costPerPound != None:

               totalCost += numPounds * costPerPound

       return totalCost

def getName(self):

       return self.name

Here is the main program:

orders = [('apples',1.0), ('oranges',3.0)]

dir1 = {'apples': 2.0, 'oranges':1.0}

shop1 =  shop.FruitShop('shop1',dir1)

dir2 = {'apples': 1.0, 'oranges': 5.0}

shop2 = shop.FruitShop('shop2',dir2)

shops = [shop1, shop2]

print("For orders ", orders, ", the best shop is", shopSmart(orders, shops).getName())

orders = [('apples',3.0)]

print("For orders: ", orders, ", the best shop is", shopSmart(orders, shops).getName())

Notice that the statement:

print("For orders ", orders, ", the best shop is", shopSmart(orders, shops).getName())

has orders list which is:

[('apples',1.0), ('oranges',3.0)]

and it has shops which is a list containing two shops:

shops = [shop1, shop2]

It also calls method shopSmart by passing orders and these two shops to get the shop where the order costs the least amount in total. It has a for loop that iterates through each shop and check the orders using getPriceOfOrder method to determine at which shop the order costs the least amount in total. When the least amount is found it is set to the variable leastAmount and the shop corresponding to this order which has least amount is set to shop variable. At the end this shop is returned by the function. getName() method is used in the main program to get the name of the shop with least amount of order cost. So above print statement gives the following output:

For orders  [('apples', 1.0), ('oranges', 3.0)] , the best shop is shop1    

The entire program along with its output is attached.                                

You might be interested in
Which is not covered under the Computer Access Device and Computer Fraud and Abuse Act (CADCFA)? unauthorized use of federal com
Mazyrski [523]

Answer:

The correct answer to the following question is "Typewriters".

Explanation:

CADCFA seems to be the very first provision of federal laws to specifically concentrate on computer assault. These clauses continued to allow corporations to prosecute unjust workers for compensation for the misuse of confidential or sensitive information.

  • Even though we all agree that sometimes a federal worker uses the typewriters in the abundance of power, that's why it's not protected by that same act.
  • The other options are incorrect because they are all known and are covered for that given CADCFA act.
5 0
3 years ago
Write a program that: Takes the list lotsOfNumbers and uses a loop to find the sum of all of the odd numbers in the list (hint:
Alika [10]

Answer:

Following are the code to this question:

#include <iostream>//defining header file

using namespace std;

int main()//defining main method

{

int x[]={2,3,4,6,7,8,9,1,11,12};//defining 1-D array and assign value

int i,sum=0;//defining integer variable

for(i=0;i<10;i++)//defining loop for count value

{

   if(x[i]%2==1)//defining if block to check odd value

   {

       sum=sum+x[i];//add value in sum variable

   }

}

cout<<sum;//print sum

return 0;

}

Output:

31

Explanation:

In the above-given program, an integer array "x" is declared that holds some integer values, and in the next line two integer variable "i and sum" is defined which is used to calculate the value.

In the next line, a for loop is declared, that counts all array value, and it uses the if block to check the odd value and add all the value into the sum variable.

5 0
3 years ago
You can use a server-side script as a ____ to access data from another domain.
Mashcka [7]
I believe the answer your looking for is "Proxy"
0 0
4 years ago
Give two reasons why mobile internet may not be available everywhere. ​
andreev551 [17]

Answer:

Mobile Internet is dependant on cellular signal. Many countries, e.g. in Africa, don't have any coverage at all. Furthermore, mobile data might also not be available in the mountains as there are no cell towers and the rough terrain usually either blocks the signal entirely or weakens it significantly.

4 0
3 years ago
Lynn has created a quarterly sales report using a word processor. The document is confidential, and Lynn wants to secure it with
sweet-ann [11.9K]
Stop cheating



It’s b
3 0
3 years ago
Other questions:
  • The point on the middle of an edge in SketchUp is called a...
    5·2 answers
  • What is the purpose of requirements gathering
    9·2 answers
  • An administrator needs to set up an authentication server for users connecting to a network through a VPN. What kind of server c
    12·1 answer
  • How to count how many uppercase letters in sentence in python?
    8·1 answer
  • Which statement describes part of the meeting scheduling process? It is always an all-day event. It is created in a single calen
    14·1 answer
  • To calculate subtotal for a table, the first step is to use the ____ button on the table tools design tab.
    15·1 answer
  • Discuss any five factors that hinder the application of a computer in business organisations​
    15·2 answers
  • Help fast pleas. 3. How is this text formatted? (1 point)
    14·1 answer
  • Question 1 of 10 Which type of information systems personnel are involved in organizing information so that users can access it
    7·1 answer
  • How is your mental health as you're returning to school virtually or in
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!