Question: Write a greedy algorithm using Python Imagine that you walk into a restaurant, and want to maximize your caloric intake while staying under your budget

 Write a greedy algorithm using Python Imagine that you walk into

Write a greedy algorithm using Python

Imagine that you walk into a restaurant, and want to maximize your caloric intake while staying under your budget of 20 dollars. You step to the counter and see your options of (with each item listed as Name, Price, Calories) . Water, $1.00, 0 Soda, $2.00, 100 Salad, $3.50, 200 . Fries, $4.00, 400 Burger, $6.50, 700 Chicken, $7.00, 500 Ice Cream, $3.00, 400 Please write and implement a greedy algorithm that maximizes your calories while staying under budget. You can do this in the notebook or in a separate file You should test three methods of choosing the "best" item: .The lowest price The highest calories The best calorie/price ratio Your code should include: -A definition of a class (Food) that stores the data for each item, and returns the proper value needed for each "best" method A function that takes in a list of names, prices and calories and returns a menu (a list of Foods) An algorithm that sorts your list, using the three condition described above, from best to worst. It should return a new sorted list, not changing the original Code that keeps a running sum of the calories and cost of your meal. This code will stop building a meal if the cost is over budget. Your code should be flexible enough to change the budget (input it as a parameter)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!