From 2250ef26b476c935dae069af2b99390cb2334eba Mon Sep 17 00:00:00 2001 From: matteorr88 Date: Tue, 30 Apr 2024 22:06:50 +0200 Subject: [PATCH 1/3] added the solution to final project --- projects/final-project/README.md | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/projects/final-project/README.md b/projects/final-project/README.md index 143a8d1..1aad4f0 100644 --- a/projects/final-project/README.md +++ b/projects/final-project/README.md @@ -17,7 +17,7 @@ The goal of the project is to create a simple tool that allows users to obtain a - Ask the user for any food preferences or restrictions and store them in a text variable. - Calculation of daily calorie requirement: -- Using only mathematical calculations, calculate the user's daily calorie needs based on their gender, age, height and weight. +- Using only mathematical calculations, calculate the ser'us daily calorie needs based on their gender, age, height and weight. Store the daily calorie requirement value in a numeric variable. Meal plan generation: @@ -32,4 +32,12 @@ If you have provided food preferences or restrictions, adjust your meal plan acc ### End of program: -Show a closing and thank you message to the user. \ No newline at end of file +Show a closing and thank you message to the user. + +user_gender = input("Please enter your gender : male/female") +user_age = int(input("please enter your age")) +user_height = int(input("please enter your height in cm")) +user_weight = int(input("please enter your weight in kg")) +user_activity = input("please enter your level of activity: sedentary/light/moderate/heavy")) +user_preferences = input("Please enter any food preferences") +user_restrictions = input("Please enter any food restrictions") \ No newline at end of file From 2465f45ffed6a88403a699453726627c8821ad70 Mon Sep 17 00:00:00 2001 From: matteorr88 Date: Tue, 30 Apr 2024 22:21:49 +0200 Subject: [PATCH 2/3] added updated solution --- projects/final-project/main.py | 64 ++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 projects/final-project/main.py diff --git a/projects/final-project/main.py b/projects/final-project/main.py new file mode 100644 index 0000000..3019dd5 --- /dev/null +++ b/projects/final-project/main.py @@ -0,0 +1,64 @@ +# check if user enters a valid gender +def is_valid_gender(gender): + gender = gender.lower() + return gender == "male" or gender == "female" + +user_gender = input("Please enter your gender (male or female): ") +if not is_valid_gender(user_gender): + print("Please enter a valid gender (male or female)).") + exit() +else: + pass + +user_age = int(input("please enter your age")) +user_height = int(input("please enter your height in cm")) +user_weight = int(input("please enter your weight in kg")) + +# check if user enters a valid activity level +def is_valid_activity(activity): + activity = activity.lower() + return activity == "sedentary" or activity == "light" or activity == "moderate" or activity == "heavy" +user_activity = input("please enter your level of activity: sedentary/light/moderate/heavy").lower() +if not is_valid_activity(user_activity): + print("please enter a valid level of activity") + exit() +else: + pass + +user_preferences = input("Please enter any food prefernces") +user_restrictions = input("Please enter any food restrictions") + +male_bmr = int(10 * user_weight + 6.25 * user_height - 5 * user_age + 5) +female_bmr = int(10 * user_weight + 6.25 * user_height - 5 * user_age - 161) +# find users BMR +if user_gender == "male": + user_bmr = male_bmr +else: + user_bmr = female_bmr +# find the users calorie need. +if user_activity == "sedentary": + user_calorie_need = user_bmr * 1.2 +elif user_activity == "light": + user_calorie_need = user_bmr * 1.375 +elif user_activity == "moderate": + user_calorie_need = user_bmr * 1.55 +elif user_activity == "heavy": + user_calorie_need = user_bmr * 1.9 + +vegetarian_foods = { + + "greek yogurt": { + "quantity": "100g", + "calories": 133, + "proteins": 23, + "carbohydrates": 9, + "fats": 0.4 + }} + +calorie_goal = int(user_calorie_need) + +calories_per_100g = vegetarian_foods["greek yogurt"]["calories"] + +quantity_of_yogurt = int(calorie_goal / calories_per_100g) * 100 + +print("to reach", calorie_goal, "kcal", "you should eat", quantity_of_yogurt, "grams of yogurt spread during your day") \ No newline at end of file From 14ce7060900a9e71af0609b7cfa3bba35bfd0f8a Mon Sep 17 00:00:00 2001 From: matteorr88 Date: Mon, 6 May 2024 19:33:02 +0200 Subject: [PATCH 3/3] updated solution --- projects/final-project/main.py | 137 ++++++++++++++++++++++++++++++--- 1 file changed, 125 insertions(+), 12 deletions(-) diff --git a/projects/final-project/main.py b/projects/final-project/main.py index 3019dd5..13e0c05 100644 --- a/projects/final-project/main.py +++ b/projects/final-project/main.py @@ -30,11 +30,13 @@ def is_valid_activity(activity): male_bmr = int(10 * user_weight + 6.25 * user_height - 5 * user_age + 5) female_bmr = int(10 * user_weight + 6.25 * user_height - 5 * user_age - 161) + # find users BMR if user_gender == "male": user_bmr = male_bmr else: user_bmr = female_bmr + # find the users calorie need. if user_activity == "sedentary": user_calorie_need = user_bmr * 1.2 @@ -45,20 +47,131 @@ def is_valid_activity(activity): elif user_activity == "heavy": user_calorie_need = user_bmr * 1.9 -vegetarian_foods = { - - "greek yogurt": { - "quantity": "100g", - "calories": 133, - "proteins": 23, - "carbohydrates": 9, - "fats": 0.4 - }} +foods = { + "Chicken Breast": { + "quantity_g": 100, + "calories": 165, + "proteins_g": 31, + "carbs_g": 0, + "fats_g": 3.6, + "type": "non-vegetarian" + }, + "Egg": { + "quantity_g": 100, + "calories": 155, + "proteins_g": 13, + "carbs_g": 1.1, + "fats_g": 11, + "type": "vegetarian" + }, + "Spinach": { + "quantity_g": 100, + "calories": 23, + "proteins_g": 2.9, + "carbs_g": 3.6, + "fats_g": 0.4, + "type": "vegetarian" + }, + "Brown Rice": { + "quantity_g": 100, + "calories": 111, + "proteins_g": 2.6, + "carbs_g": 23, + "fats_g": 0.9, + "type": "vegetarian" + }, + "Salmon": { + "quantity_g": 100, + "calories": 208, + "proteins_g": 20, + "carbs_g": 0, + "fats_g": 13, + "type": "non-vegetarian" + }, + "Broccoli": { + "quantity_g": 100, + "calories": 34, + "proteins_g": 2.8, + "carbs_g": 6, + "fats_g": 0.4, + "type": "vegetarian" + }, + "Greek Yogurt": { + "quantity_g": 100, + "calories": 59, + "proteins_g": 10, + "carbs_g": 3.6, + "fats_g": 0.4, + "type": "vegetarian" + }, + "Tofu": { + "quantity_g": 100, + "calories": 76, + "proteins_g": 8, + "carbs_g": 1.9, + "fats_g": 4.8, + "type": "vegan" + }, + "Almonds": { + "quantity_g": 100, + "calories": 579, + "proteins_g": 21, + "carbs_g": 22, + "fats_g": 49, + "type": "vegetarian" + }, + "Black Beans": { + "quantity_g": 100, + "calories": 339, + "proteins_g": 21, + "carbs_g": 63, + "fats_g": 1.4, + "type": "vegetarian" + } +} calorie_goal = int(user_calorie_need) -calories_per_100g = vegetarian_foods["greek yogurt"]["calories"] +import random + +# Function to generate a diet plan with a random food item +def generate_diet(foods, calorie_goal): + random_food = random.choice(list(foods.keys())) + calories_per_100g = foods[random_food]["calories"] + quantity_of_food = int(calorie_goal / calories_per_100g) * 100 + return random_food, quantity_of_food + +# Check if user preferences are in the food list +preferred_foods = {} +for food, info in foods.items(): + if user_preferences.lower() in food.lower(): + preferred_foods[food] = info + +# If user preferences are not in the food list, inform the user and proceed with a random food +if not preferred_foods: + print("Sorry, one or more of your preferred foods are not in this diet. Proceeding with a random food.") + random_food, quantity_of_food = generate_diet(foods, calorie_goal) + print("To reach your daily calorie need you should eat: ") + print(f"- {random_food}: {quantity_of_food} grams") +else: + # Generate diet plan using preferred foods + # Code to generate diet plan using preferred foods... + pass -quantity_of_yogurt = int(calorie_goal / calories_per_100g) * 100 +#FIlter foods +preferred_foods = {} +for food, info in foods.items(): + if user_preferences.lower() in food.lower(): + preferred_foods[food] = info -print("to reach", calorie_goal, "kcal", "you should eat", quantity_of_yogurt, "grams of yogurt spread during your day") \ No newline at end of file +# calculate portions of preferred food +diet_plan = {} +for food, info in preferred_foods.items(): + calories_per_100g = info["calories"] + quantity = int(calorie_goal / calories_per_100g) * 100 + diet_plan[food] = {"quantity": quantity, **info} + +# Display + print("To reach your daily calorie need you should eat: "), calorie_goal + for food, info in diet_plan.items(): + print(f"- {food}: {info['quantity']} grams") \ No newline at end of file