# Function to simulate meal nutrition data based on user input, including calories
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.")
# Calculate calories based on macronutrients (approximate formula)
calories = 4 * carbs + 4 * proteins + 9 * fats
meal_carbs.append(carbs)
meal_proteins.append(proteins)
meal_fats.append(fats)
meal_fiber.append(fiber)
meal_calories.append(calories)
break
except ValueError as e:
print(f"Invalid input: {e}")
return meal_carbs, meal_proteins, meal_fats, meal_fiber, meal_calories,
meal_names
# Function to analyze meal nutrition and provide suggestions
def analyze_meal_nutrition(meal_carbs, meal_proteins, meal_fats, meal_fiber,
meal_names):
suggestions = []
for i in range(len(meal_carbs)):
# Example suggestion logic: compare protein content to a recommended
range
total_protein = meal_proteins[i]
if total_protein < 15:
suggestion = f"For {meal_names[i]}, consider adding more protein to
balance your meal."
elif total_protein > 30:
suggestion = f"For {meal_names[i]}, you may want to reduce the protein
intake for better balance."
else:
suggestion = f"For {meal_names[i]}, your protein intake looks balanced."
suggestions.append(suggestion)
return suggestions
# Main function to get user information and run the simulation
def main():
print("Welcome to the Meal Nutrition and Calorie Analyzer for Diabetes")
print("--------------------------------------------------------------")
name, age = get_user_info()
meals = 4 # Number of meals per day (Breakfast, Lunch, Dinner, Snacks)
print(f"\nHello {name}, age {age}!")
print("Please enter nutrition details for each meal type.")
meal_carbs, meal_proteins, meal_fats, meal_fiber, meal_calories, meal_names =
simulate_meal_nutrition(meals)
# Analyze meal nutrition and provide suggestions
suggestions = analyze_meal_nutrition(meal_carbs, meal_proteins, meal_fats,
meal_fiber, meal_names)
# Example: Print meal nutrition, calorie data, and suggestions
for i in range(meals):
print(f"\nMeal {i + 1} - Carbs: {meal_carbs[i]}g, Proteins: {meal_proteins[i]}g,
Fats: {meal_fats[i]}g, Fiber: {meal_fiber[i]}g, Calories: {meal_calories[i]}")
print(f"Suggestion: {suggestions[i]}")
# Example: Calculate total daily nutrition and calories
total_carbs = sum(meal_carbs)
total_proteins = sum(meal_proteins)
total_fats = sum(meal_fats)
total_fiber = sum(meal_fiber)
total_calories = sum(meal_calories)
print(f"\nTotal Daily Nutrition - Carbs: {total_carbs}g, Proteins: {total_proteins}g,
Fats: {total_fats}g, Fiber: {total_fiber}g, Calories: {total_calories}kcal")
# Entry point of the script
if __name__ == "__main__":
main()
118
import numpy as np
import matplotlib.pyplot as plt
# Function to simulate daily glucose levels based on user input
def simulate_glucose_levels(times_of_day):
glucose_levels = []
# 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
# Main function to get user information and run the simulation
def main():
print("Welcome to the Diabetes Risk Analyzer")
print("------------------------------------")
name = input("Enter your name: ")
age = int(input("Enter your age: "))
times_of_day = ['Morning', 'Afternoon', 'Evening', 'Night']
print(f"\nHello {name}, age {age}!")
print("Please enter your glucose levels for each time of the day.")
glucose_levels = simulate_glucose_levels(times_of_day)
# Determine the safe range for glucose levels (example ranges)
safe_low = 70
safe_high = 180
# Plotting the glucose levels with risk indication
plt.figure(figsize=(8, 6))
bars = plt.bar(times_of_day, glucose_levels, color='orange', alpha=0.7)
# Add labels and grid
plt.title('Daily Glucose Levels')
plt.xlabel('Time of Day')
plt.ylabel('Glucose Level (mg/dL)')
plt.ylim(0, 300) # Adjust ylim based on expected glucose range
# Highlight bars outside the safe range
for i in range(len(bars)):
if glucose_levels[i] < safe_low:
bars[i].set_color('red') # Low glucose level (risk)
elif glucose_levels[i] > safe_high:
bars[i].set_color('purple') # High glucose level (risk)
# Add legend for risk levels
plt.legend(handles=[
plt.Rectangle((0,0),1,1,color='red',label='Low Risk'),
plt.Rectangle((0,0),1,1,color='purple',label='High Risk')
])
plt.show()
# Entry point of the script
if __name__ == "__main__":
main()