Main content
Iterating over lists with loops
Problem
A nutrition scientist is working on code to calculate the most magnesium-rich foods.
Their program processes a list of numbers representing milligrams of magnesium in servings of food. The goal of the program is to create a new list that contains only the numbers that represent at least 30% of the recommended daily intake of 360 milligrams.
mgAmounts ← [50, 230, 63, 98, 80, 120, 71, 158, 41]
bestAmounts ← []
mgPerDay ← 360
mgMin ← mgPerDay * 0.3
FOR EACH mgAmount IN mgAmounts
{
IF (mgAmount ≥ mgMin)
{
<MISSING CODE>
}
}
A line of code is missing, however.
What can replace
<MISSING CODE>
so that this program will work as expected???Note that there may be multiple answers to this question.
?
Related content