Cheap Vegan Eats

Data with PythonEasy+10 XP+10

Cheap Vegan Eats

A café menu is a list of dictionaries. Each dish has a dish name, a diet and a price in pounds. diet is always one of "vegan", "veggie" or "meat", written in lowercase.

A customer wants something vegan that costs less than their budget.

Task: write cheap_vegan_count(menu, budget).

  • Turn menu into a DataFrame.
  • Keep the dishes whose diet is "vegan" and whose price is less than budget. A dish that costs exactly budget doesn't count.
  • Return how many dishes are left, as a whole number. If none are left, return 0.

menu always has at least one dish.

Examples

menu = [{"dish": "falafel wrap", "diet": "vegan", "price": 6.5}, {"dish": "cheese toastie", "diet": "veggie", "price": 4.2}, {"dish": "lentil soup", "diet": "vegan", "price": 3.9}, {"dish": "ham roll", "diet": "meat", "price": 3.5}]
budget = 5
returns 1
menu = [{"dish": "chips", "diet": "vegan", "price": 2.5}, {"dish": "bean chilli", "diet": "vegan", "price": 7.0}, {"dish": "fruit pot", "diet": "vegan", "price": 2.0}]
budget = 10
returns 3

Hints

Solve it to unlock the solution

Once your code passes every test, a reference solution shows up here so you can compare it with yours.

solution.py
CtrlEnterto run