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
Is this free? do i have to pay to use this app??
Virty [35]
No i don’t have to pay but there is additional stuff if you pay but i don’t pay for anything
3 0
3 years ago
. An exception is an error that occurs during the execution of a program at run-time that disrupts the normal fow of the Java pr
In-s [12.5K]

Answer: True

Explanation:Exception error ,which is also known as the fatal error that arises when there is the program execution going-on and the error occurs suddenly to stop the processing, resulting in the abortion of the execution.This erruptional error is responsible for disturbing the execution flow as well as there are chances of the data getting lost or deleted automatically.

5 0
4 years ago
Which type of URL gives an abbreviated path to a resource using the current page as a starting position?
lilavasa [31]

A relative URL is a type of URL that gives an abbreviated path to a resource by using the current webpage as a starting position.

<h3>What is a relative URL?</h3>

A relative URL can be defined as a type of URL that doesn't contain or use the full address of a website, but only the path (location) following the domain name.

This ultimately implies that, a relative URL is a type of URL that gives an abbreviated path (location) to a web resource by using the current webpage as a starting position.

Read more on relative URL here: brainly.com/question/26670945

#SPJ12

6 0
2 years ago
You have a group of friends coming to visit you for your high school reunion, and you want to take them out to eat at a local re
-BARSIC- [3]

Answer:

Python code is explained below

Explanation:

def RestaurentSelector():

               #stroring the restaurants data

               restaurents=[["Joe's Gourmet Burgers","no","no","yes"],["Main Street Pizza Company","yes","yes","yes"],["Corner Cafe","yes","no","yes"],["Mama's Fine Italian","yes","no","no"],["The Che'fs Kitchen","yes","yes","yes"]]

               #taking the requirements for party

               isVeg=input("Is anyone at your party a vegetarian? ")

               isVegan=input("Is anyone at your party a vegan? ")

               isGF=input("Is anyone at your party a gluten-free? ")

               #printing the info

               print("Hera are your restaurant choices :")

               #loop to check each restaurent

               for x in restaurents:

                               #checking for veg requirement

                               if isVeg=="yes" and x[1]=="no":

                                               #skipping the current restaurent if is satisfying

                                               continue

                               #checking for vegan requirement

                               if isVegan=="yes" and x[2]=="no":

                                               #skipping the current restaurent if is satisfying

                                               continue

                               #checking for glutan free requirement

                               if isGF=="yes" and x[3]=="no":

                                               #skipping the current restaurent if is satisfying

                                               continue

                               #if all requirementws are satisfied

                               #printing the restaurent name

                               print("\t",x[0])

               #exiting the function\

#calling the function

RestaurentSelector()

4 0
3 years ago
Drag each label to the correct location on the image
tamaranim1 [39]

Answer:

huhhhhhhhhhhhhhhhhhhhh

7 0
3 years ago
Read 2 more answers
Other questions:
  • In Python, if var1 = “Happy” and var2= “Birthday” and var3 = (var1+var2) *2, then var3 stores the string
    15·1 answer
  • What is the difference between operating systems and application software?
    6·2 answers
  • I am doing 7th grade coding 3.02 assignment can anybody help me it says bad input on line 3 and this is what it is can someone h
    6·1 answer
  • True or False The two types of general construction projects are residential for homes or dwellings and commercial for a commerc
    7·1 answer
  • Please its argent and I will give you BRAINLIEST ANSWER 6. How would you confirm that a colourless liquid given to you is pure w
    10·1 answer
  • To display data in a certain manner, like alphabetical order, is called
    14·1 answer
  • What’s cloud-based LinkedIn automation?
    14·1 answer
  • Write 3 3 advantage and disadvantage of computer​
    10·1 answer
  • An intruder can wreak havoc on a network by simply plugging in an infected USB flash drive.
    7·1 answer
  • A packet switch has 5 users, each offering packets at a rate of 10 packets per second. The average length of the packets is 1,02
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!