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
What usually happens at a police check? Do they just look up your name in their system?
sdas [7]

it depends on the kind of police check. like if its a road block type of check, they make sure everything is right. if you get pulled over you get your name ran in the system to check if you have warrents or warning and depends on what you get pulled over for, you could get a ticket or detained.

5 0
4 years ago
Pick two programming languages. Please describe: - The major differences between those two languages; and - If you were assessin
kiruha [24]

First language : JAVA

Second Language : C++

Major Difference :

1. Platform Dependency :

Java is platform independent which means that its code can be run on any machine. It uses JVM ( Java virtual machine ) which converts the code in byte form and then run it which makes it flexible enough to be used on any system. So .exe file can run on any OS.

C++ is not platform independent and thus its .exe file  cannot be run on different OS.

2. Objects

In JAVA everything is reference typed and is inherited from the class objects that are predefined in it.

In C++ not everything is class or reference typed.

3. Garbage Collector

Java has built in garbage collector when we use classes in java.

C++ make developer to collect garbage when he uses reference types like pointers.

Why choose Java and C++ ?

People are very confused about the platform in-dependency of JAVA, so i decided to choose Java and compared that concept with c++ which is mother of all languages.

8 0
4 years ago
Cylinder heads with four valves flow more air than those with two valves because they
Effectus [21]
Are able to hold more air
8 0
3 years ago
URGENT!!! While using her digital camera to photograph her new couch in her living room, Amy uses the white balance setting that
nirvana33 [79]

Answer:  A. Fluorescent

Explanation:    Bc I'm always right :)

5 0
3 years ago
Read 2 more answers
Ben has to write a note on color concepts. Help him complete the following sentences.
k0ka [10]
<span>Ben has to write a note on color concepts. Help him complete the following sentences.
When light hits a surface, the surface absorbs some of the light and reflects the rest. The color that you see depends on which light waves the surface reflects
( reflects, absorbs, emits) the most. You perceive objects as having a specific color because of these constituent ______( rays, colors, intensities) of light.

I wasn't sure on the last one.</span>
5 0
4 years ago
Read 2 more answers
Other questions:
  • _______ is the component of the information system that is described as the equipment that processes data to create information.
    6·1 answer
  • Classify the following skills: preparing a presentation, rebuilding a car, and solving equations.
    11·2 answers
  • A proxy is
    6·1 answer
  • What does “modulate your voice” mean?
    9·1 answer
  • First person to answer gets free brainlist
    15·2 answers
  • 7. A patent is an example of a rare and valuable resource. Indicate whether the statement is true or false and also justify it.
    14·1 answer
  • What charts the cost to the company of the unavailability of information and technology and the cost to the company of recoverin
    15·1 answer
  • Braxton is writing a program to design t-shirts. Which of the following correctly sets an attribute for color?
    7·1 answer
  • How much tabs can you open with 8GB of ram? ​
    6·1 answer
  • What is the best way of farming exotics in destiny?
    12·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!