Coding
Coding
def simulate_meal_nutrition(meals):
meal_names = ['Breakfast', 'Lunch', 'Dinner', 'Snacks']
meal_carbs = []
meal_proteins = []
meal_fats = []
meal_fiber = []
meal_calories = []
# Prompt user to enter meal nutrition data for each meal type
for meal in range(meals):
while True:
try:
print(f"Enter nutrition details for {meal_names[meal]}:")
carbs = float(input("Carbohydrates (g): "))
proteins = float(input("Proteins (g): "))
fats = float(input("Fats (g): "))
fiber = float(input("Fiber (g): "))
if any(nutrient < 0 for nutrient in [carbs, proteins, fats, fiber]):
raise ValueError("Nutrient values cannot be negative.")
# Prompt user to enter glucose levels for each time of the day
for time in times_of_day:
while True:
try:
glucose = float(input(f"Enter glucose level for {time}: "))
if glucose < 0:
raise ValueError("Glucose level cannot be negative.")
glucose_levels.append(glucose)
break
except ValueError as e:
print(f"Invalid input: {e}")
return glucose_levels
glucose_levels = simulate_glucose_levels(times_of_day)
plt.show()