Question

In this problem I want to return a grocery store dictionary with the name as the...

In this problem I want to return a grocery store dictionary with the name as the key and the price the value. The price must be less than my budget and the distance must be less than maxDistance. So the output for this problem should be {'Kroger': 2.79, 'Walgreens': 1.99, 'Sprouts': 3.45} . This is the code that I have, but it returns an IndexError.

def friendsgiving(stores, budget, maxDistance):
    if stores == [] and budget == 0 and maxDistance == 0:
        return {}
    else:
        storeDict = {}
        (name, price, distance) = stores[0]
        friendsgiving(stores[1:], budget, maxDistance)
        if price < budget and distance < maxDistance:
            return storesDict[name] == price
print(friendsgiving( [('Sprouts', 3.45, 2),('ALDI', 3.69, 6),('Walgreens', 1.99, 1),('Kroger', 2.79, 4)], 3.50, 5))

Homework Answers

Answer #1
def friendsgiving(stores, budget, maxDistance):
    if stores == [] and budget == 0 and maxDistance == 0:
        return {}
    else:
        storeDict = {}
        for i in range(len(stores)):
            (name, price, distance) = stores[i]
            if price < budget and distance < maxDistance:
                storeDict.update({name:price})
    return storeDict 
print(friendsgiving( [('Sprouts', 3.45, 2),('ALDI', 3.69, 6),('Walgreens', 1.99, 1),('Kroger', 2.79, 4)], 3.50, 5))

I Have made the necessary changes and got the output.Hope it helps you.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
## We will be simulating the ideal solution to Hanoi's tower problem. ## The discs will...
## We will be simulating the ideal solution to Hanoi's tower problem. ## The discs will be numers from 0 to n-1, with the larger number being the smaller disc. ## each rod with discs will be encoded by a list, from bottom to top. For example, a rod with discs 0, 3, 5 will be encoded as [0,3,5] ## current configuration of rods will be encoded as a list of 3 lists. For example, starting state with 3 discs...
So, i have this code in python that i'm running. The input file is named input2.txt...
So, i have this code in python that i'm running. The input file is named input2.txt and looks like 1.8 4.5 1.1 2.1 9.8 7.6 11.32 3.2 0.5 6.5 The output2.txt is what i'm trying to achieve but when the code runs is comes up blank The output doc is created and the code doesn't error out. it should look like this Sample Program Output 70 - 510, [semester] [year] NAME: [put your name here] PROGRAMMING ASSIGN MENT #2 Enter...
I NEED TASK 3 ONLY TASK 1 country.py class Country:     def __init__(self, name, pop, area, continent):...
I NEED TASK 3 ONLY TASK 1 country.py class Country:     def __init__(self, name, pop, area, continent):         self.name = name         self.pop = pop         self.area = area         self.continent = continent     def getName(self):         return self.name     def getPopulation(self):         return self.pop     def getArea(self):         return self.area     def getContinent(self):         return self.continent     def setPopulation(self, pop):         self.pop = pop     def setArea(self, area):         self.area = area     def setContinent(self, continent):         self.continent = continent     def __repr__(self):         return (f'{self.name} (pop:{self.pop}, size: {self.area}) in {self.continent} ') TASK 2 Python Program: File: catalogue.py from Country...
Below is the problem that I have and here is the code that I have in...
Below is the problem that I have and here is the code that I have in c++. Can someone help me on what I am doing wrong or the correct code. A teacher has asked all her students to line up according to their first name. For example, in one class Amy will be at the front of the line, and Yolanda will be at the end. Write a program that prompts the user to enter the number of students...
EVERYTHING HAS TO BE DONE IN C#. (I need pseudocode and source code please) Problem Statement:...
EVERYTHING HAS TO BE DONE IN C#. (I need pseudocode and source code please) Problem Statement: Write an abstract class called Vacation that includes three class variables named: cost, budget, and destination. It has an abstract method, KeptToBudget, returning how much the vacation is over or under budget using cost. This class has two non-abstract subclasses, each with their own class variables: All-Inclusive Vacation: brand (such as ClubMed, Delta Vacations, etc.) rating (number of stars) total cost (all-inclusive means that...
PLEASE ANSWER C!!! Bob & Betty Homebuyers want to make an offer on this property at...
PLEASE ANSWER C!!! Bob & Betty Homebuyers want to make an offer on this property at the list price. Bob earns $48,000 per year and Betty earns $54,000 per year. They have very good credit. Their monthly payments are $200 for student loans, $350 for their car payment and minimum credit card payment of $50. They have savings of $125,000. The balance of their student loans is $40,000. Insurance on this house will cost them $900 per year. Property taxes...
I was asked to write a program in CodeBlocks. C++ format. I've written the first half...
I was asked to write a program in CodeBlocks. C++ format. I've written the first half of the code but I am using else and if statements. I feel like the code is too long to do a simple calculation. In CodeBlock when you build and run your code, a new terminal window opens (in windows a new console window) and you can enter your inputs there. It is not like eclipse that you enter your inputs in console view....
Assessment Module 9 – Marginal Analysis Please create a tab in your Excel Workbook and name...
Assessment Module 9 – Marginal Analysis Please create a tab in your Excel Workbook and name it “Module 9 Marginal Analysis.” You have same basic templates in your Resources workbook, but you may need to modify these to fit the individual business problem. I am evaluating your professional ability to do so, and to create professional models and reports, so take your time, think through a logical, clear, well-structured, well-formatted model. Remember, assumption tables (like T-accounts) are your friends! Be...
Kimmel Gnomes DATE:​March 1, 2018 TO:​CCSU Consulting FROM:​Candice Kimmel, President, Kimmel Gnomes SUBJECT:​Master Budget for the...
Kimmel Gnomes DATE:​March 1, 2018 TO:​CCSU Consulting FROM:​Candice Kimmel, President, Kimmel Gnomes SUBJECT:​Master Budget for the fiscal year July 1, 2018 – June 30, 2019 ---------------------------------------------------------------------------------------------------------------------------------- Our controller, Richard Kimmel is negotiating with potential new Clay suppliers in Kentucky. We need the Large Gnome Division’s Master Budget for the fiscal year ended June 30, 2019 for our corporate strategic planning process, and we cannot wait for Richard’s return from Kentucky. We would like you to prepare the Large Gnome Division’s...
Please answer the following Case analysis questions 1-How is New Balance performing compared to its primary...
Please answer the following Case analysis questions 1-How is New Balance performing compared to its primary rivals? How will the acquisition of Reebok by Adidas impact the structure of the athletic shoe industry? Is this likely to be favorable or unfavorable for New Balance? 2- What issues does New Balance management need to address? 3-What recommendations would you make to New Balance Management? What does New Balance need to do to continue to be successful? Should management continue to invest...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT