Status: Not Started
  • scratchpad.py
  • Unit Test
Font Size
14
Parentheses autocomplete
Wrap lines
Editor
Theme
Code with blocks by default
Console Font Size
12
Console Theme
Display Server Graphics Screen
Show File Tab Bar
Debug Mode
Shopping on a Budget
Unit Test
def shopping(budget, num_items, avg_costs):
return
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Output
Grading
Docs
Exercise
More
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
Pass Test Message

Errors:

This student is viewing this assignment in English. View this page in English?

5 points

You’re going on a shopping trip! But you only have a certain amount of money to spend.

Write a function that takes in:
1. budget: the total amount of money you have to spend,
2. num_items: the number of items you want to buy,
3. avg_costs: a dictionary where the keys are store names and the values are the average cost per item at each store.

The function should return a list of store names where you can afford to buy the number of items within your budget. You can afford a store if the total cost (number of items * average cost per item) is less than or equal to your budget.

Example:
budget = 100
num_items = 5
avg_costs = {"Store A": 15, "Store B": 30, "Store C": 18}

# The total cost at Store A is 15 * 5 = 75, which is within the budget.
# The total cost at Store B is 30 * 5 = 150, which exceeds the budget.
# The total cost at Store C is 18 * 5 = 90, which is within the budget.

# So, the function should return ["Store A", "Store C"]
Python
Reset Code

Slides and Notes

No slides available for this video

About

Python 3 Practice
3.11.9 (default, Apr 6 2024, 17:59:24)
[GCC 6.4.0]