I need the program to print the line "Meal options:" only when there is enough money.
I need the program to print the line "Meal options:" only when there is enough money.
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
Related questions
Question
I need the program to print the line "Meal options:" only when there is enough money.
def get_possible_meals(budget, num_persons):
tacos_cost = 4
empanandas_cost = 3
max_tacos = budget // tacos_cost
max_empanadas = budget // empanandas_cost
feasible = False
print("\nMeal options:")
for num_tacos in range (max_empanadas + 1):
num_empanadas = (budget - num_tacos * tacos_cost) // empanandas_cost
if num_empanadas > 0andnot (num_empanadas + num_tacos) % num_persons:
feasible = True
total_cost = num_tacos * tacos_cost + num_empanadas * empanandas_cost
change = budget - total_cost
print(f'${total_cost} buys {num_empanadas} empanadas and {num_tacos} tacos with ${change} change. {(num_empanadas + num_tacos) // num_persons} items per person.')
ifnot feasible:
print(f'You cannot buy a meal with these options.')
def main():
budget = int(input('Enter budget for meal: $'))
num_people = int(input('How many people are eating: '))
get_possible_meals(budget, num_people)
if __name__ == '__main__':
main()
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images
Recommended textbooks for you
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)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
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)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education