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...
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...
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...