Question: Party budget planning - complex Prompt the user to enter their current budget and the number of people who need to share a meal. You are ordering food from a restaurant that has two menu items: Tacos $4 Empanadas $3 Calculate and print out all the options of meals where the budget is used entirely(where possible) and each person has an equal number of items to eat. They may eat different things, but everyone gets the same number of food items, e.g. 2 tacos or 1 empanada and 1 taco or 2 empanadas. Hints: Here are some things that might help you in your solution. If total items purchased does not equally divide by the number of diners, then abandon that combination. It may help to calculate the max number of empanadas that the budget can buy and also the max number of tacos that the budget could buy. These can be thought of as upper bounds in your loops. In your solution, keep track of items per person Also, keep track of total number of viable solutions, as that might help you determine when there is no solution. My solution is printing "You cannot buy a meal with these options." multiple times even when it is possible to buy a meal. Also my solution does show "Meal options:" before printing all of the alternatives.  I've attached the outcome that the program should be displaying and my current code.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Question: Party budget planning - complex

Prompt the user to enter their current budget and the number of people who need to share a meal.

You are ordering food from a restaurant that has two menu items:

  • Tacos $4

  • Empanadas $3

Calculate and print out all the options of meals where the budget is used entirely(where possible) and each person has an equal number of items to eat. They may eat different things, but everyone gets the same number of food items, e.g. 2 tacos or 1 empanada and 1 taco or 2 empanadas.

Hints: Here are some things that might help you in your solution.

  • If total items purchased does not equally divide by the number of diners, then abandon that combination.
  • It may help to calculate the max number of empanadas that the budget can buy and also the max number of tacos that the budget could buy. These can be thought of as upper bounds in your loops.
  • In your solution, keep track of items per person
  • Also, keep track of total number of viable solutions, as that might help you determine when there is no solution.

My solution is printing "You cannot buy a meal with these options." multiple times even when it is possible to buy a meal. Also my solution does show "Meal options:" before printing all of the alternatives. 

I've attached the outcome that the program should be displaying and my current code. 

Enter budget for meal: $100
How many people are eating: 6
Meal options:
$98 buys 22 empanadas and 8 tacos with $2 change.
5 items per person.
$99 buys 21 empanadas and 9 tacos with $1 change.
5 items per person.
$100 buys 20 empanadas and 10 tacos without change. 5 items per person.
or
Enter budget for meal: $33
How many people are eating: 15
You cannot buy a meal with these options.
Transcribed Image Text:Enter budget for meal: $100 How many people are eating: 6 Meal options: $98 buys 22 empanadas and 8 tacos with $2 change. 5 items per person. $99 buys 21 empanadas and 9 tacos with $1 change. 5 items per person. $100 buys 20 empanadas and 10 tacos without change. 5 items per person. or Enter budget for meal: $33 How many people are eating: 15 You cannot buy a meal with these options.
def get_possible_meals ( budget, num_persons):
tacos_cost = 4
empanandas_cost
= 3
budget // tacos_cost
budget // empanandas_cost
max tacos =
max_empanadas
feasible = False
for num_tacos in range (max_empanadas + 1):
num_empanadas
if num_empanadas > 0 and not (num_empanadas + num_tacos) % num_persons:
feasible = True
(budget
num_tacos * tacos_cost) // empanandas_cost
total_cost
num_tacos * tacos_cost + num_empanadas * empanandas_cost
%3D
change
budget
total_cost
%3D
print(f'${total_cost} buys {num_empanadas} empanadas and {num_tacos} tacos with ${change} change.')
print(f'{(num_empanadas + num_tacos) // num_persons} items per person.')
if not feasible:
print(f'You cannot buy a meal with these options.')
def main() :
budget
int(input('Enter budget for meal: $'))
num_persons
int(input('How many people are eating: '))
get_possible_meals(budget, num_persons)
main__':
if
name
==
main()
→ Enter budget for meal: $100
How many people are eating: 6
You cannot buy a meal with these options.
You cannot buy a meal with these options.
You cannot buy a meal with these options.
You cannot buy a meal with these options.
You cannot buy a meal with these options.
You cannot buy a meal with these options.
You cannot buy a meal with these options.
You cannot buy a meal with these options.
$98 buys 22 empanadas and 8 tacos with $2 change.
5 items per person.
Transcribed Image Text:def get_possible_meals ( budget, num_persons): tacos_cost = 4 empanandas_cost = 3 budget // tacos_cost budget // empanandas_cost max tacos = max_empanadas feasible = False for num_tacos in range (max_empanadas + 1): num_empanadas if num_empanadas > 0 and not (num_empanadas + num_tacos) % num_persons: feasible = True (budget num_tacos * tacos_cost) // empanandas_cost total_cost num_tacos * tacos_cost + num_empanadas * empanandas_cost %3D change budget total_cost %3D print(f'${total_cost} buys {num_empanadas} empanadas and {num_tacos} tacos with ${change} change.') print(f'{(num_empanadas + num_tacos) // num_persons} items per person.') if not feasible: print(f'You cannot buy a meal with these options.') def main() : budget int(input('Enter budget for meal: $')) num_persons int(input('How many people are eating: ')) get_possible_meals(budget, num_persons) main__': if name == main() → Enter budget for meal: $100 How many people are eating: 6 You cannot buy a meal with these options. You cannot buy a meal with these options. You cannot buy a meal with these options. You cannot buy a meal with these options. You cannot buy a meal with these options. You cannot buy a meal with these options. You cannot buy a meal with these options. You cannot buy a meal with these options. $98 buys 22 empanadas and 8 tacos with $2 change. 5 items per person.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education