Apply your knowledge to build something amazing!
Go to EduBlocks page and login with your Google account: https://app.edublocks.org/login
Everytime you want to start a new project, click on the "Editor" icon. To resume your project, click on the "Projects" icon.
Note: Make sure you have the habit of saving once in a while to avoid losing progress.
Using the Pygal module, let's create a chart that shows 3 macronutrients of your meal!
The macronutrients we're talking about are the carbs (carbohydrates), fat & protein.
Pick your meal of the day and start plotting the food you ate for that meal. For example, if you had rice with mutton curry and okra, you will have to find the amount of carbs, fat & protein of the 3 foods per 100grams.
The purpose of this is to identify what your food contributes to your diet on a graph.
One. Import these modules:
2. Declare initial values:
3. Add food data labels to your meal chart.
What you'll need is the value of carbs, fat and protein per 100g of a food in your meal
Find around 3 to 5 food items that best describe your meal
You can find the data of a particular food at the Malaysian Food Composition Database (MyFCD)
Within the MyFCD page you can pick browse the:
As different countries have different types of local foods and products, if you're from a country outside of Malaysia, you can check your country's respective food data. Also called food composition database
Sometimes the food data list is incomplete and missing some foods. Try searching for alternatives that best describe the missing food
Once you have added the foods of your meal, render your chart
Now we are going to edit this so that you can see the proportions of each food accurately.
To do so, we will have to put the food data into list variables so we don't keep repeating the values ourselves.
4. Rather than directly writing the values in the Pygal .add() block, use lists to represent the food name and food values.
Create a list called food_list and set the items as the name of your foods
Create a list called food_values and set the items as a list with the food values in it
5. By using the # your own code block and a range() for loop, you can add the food data to the first chart called meal.
meal.add(food_list[i], food_values[i])
The i is the index of the loop for each item in a list.
6. Render the first chart meal.
For the second chart we will be asking for the input of each of the foods in your meal. The input would be the amount of grams you ate for that food. If you have 4 foods in your meal, there will be an input for 4 of the foods.
One. Declare a second Pygal chart called meal_2.
2. Give a title called My Meal - Nutritional Value per Meal.
3. Give a list with 3 items for x_labels:
4. Print the message saying: "Let's get the amount of grams you ate for each food."
5. Use the range() for loop and repeat each of the foods you have for your meal.
You can use the loop index to get the name of the food name from the list: food_list[i]
nutrient per 100g / (100/input_grams)
Remember to use the parenthesis () according to the formula. This is called precedence, to determine which calculation to do first.
The nutrient per 100g would be the carbs, fat or protein of the individual item in food_values.
To get the value of the individual food nutrient, you can use the list bracket index twice to get the nested list item value:
The i is the index of the loop for each item in a list.
meal_2.add(food_list[i], [total_carbs, total_fat, total_pro])
Finally, render the meal_2 chart.
Make sure your Nutritious Meal project includes:
When you have completed your "Nutritious Meal" project, submit it using the link below: Submit Your Project Here Make sure to test your program before submitting to ensure all required elements are working properly!
Note: You need to submit 1 project link for this project - the advanced version which incorporates all the concepts from the basic version.