With your high school reunion fast approaching, you decide to get in shape and lose some weight. You record your weight every day for five weeks starting on a Monday.
Given these daily weights, build an array with your average weight per weekend1.
Solution¶
Explanation
We can use slicing to get the weights for every Saturday. (Keep in mind, index 0 represents a Monday, so the first Saturday occurs at index 5.)
Similarly, we can use dailywts[6::7]
to select the weights for every Sunday.
We can calculate the total weight per weekend by adding these same-sized arrays.
Lastly, we can get the average weight per weekend by dividing by the previous array by 2.
Footnotes
-
A weekend includes Saturday and Sunday (but not Friday). ↩