You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: pretext/functions/funcWithListsAndLoops.ptx
+20-42Lines changed: 20 additions & 42 deletions
Original file line number
Diff line number
Diff line change
@@ -155,27 +155,30 @@ main()
155
155
</input>
156
156
</program>
157
157
</exercise>
158
-
<exerciselabel="flal_avg_drop_high_and_low">
158
+
159
+
<exerciselabel="flal_ac_sum_first_half">
159
160
<statement>
160
-
<p>Write a function <c>avg_with_drop</c> that takes a list, <c>num_list</c> and returns the average of the values in the list, but it does not include the highest or lowest value in the average. For example, <c>avg_with_drop([1,2,3,4])</c> should return <c>2.5</c>.</p>
161
+
<p>Write a function <c>sum_first_half</c> that takes a list and returns a the sum of just the first half of the items.
162
+
For example, <c>sum_first_half([1,2,3,4])</c> should return ``3`` (sum of 1 and 2) and <c>first_half([7,8,9])</c> should return ``7``. </p>
<p>This is what the list looks like before the pop executes.</p>
243
-
</feedback>
244
-
</choice>
245
240
<choice>
246
241
<statement>
247
242
<p>[5, 7, 3]</p>
@@ -370,6 +365,7 @@ list_trans(l1)
370
365
<subsectionxml:id="flal_the-for-each-loop">
371
366
<title>The For-Each Loop</title>
372
367
<p>A for-each loop in Python will loop though the items in a list starting with the item at index 0, then index 1, and so on till the last item in the list.</p>
368
+
373
369
<exerciselabel="flal_ll_fitb_count_odd_first">
374
370
<statement>
375
371
<p>What is the first thing that will be printed by the code below? <var/> </p>
@@ -389,25 +385,8 @@ list_trans(l1)
389
385
</var>
390
386
</setup>
391
387
</exercise>
392
-
<exerciselabel="flal_ll_fitb_count_odd_last">
393
-
<statement>
394
-
<p>What is the last thing that will be printed by the code below? <var/> </p>
395
-
</statement>
396
-
<setup>
397
-
<var>
398
-
<conditionnumber="0">
399
-
<feedback>
400
-
<p>It will print the number of values that are odd in the last list which is zero.</p>
401
-
</feedback>
402
-
</condition>
403
-
<conditionstring=".*">
404
-
<feedback>
405
-
<p>Run the code to check.</p>
406
-
</feedback>
407
-
</condition>
408
-
</var>
409
-
</setup>
410
-
</exercise>
388
+
389
+
411
390
<exerciselabel="flal_ll_ac_count_odd">
412
391
<statement>
413
392
<p>Run this code to see what it prints.</p>
@@ -533,7 +512,7 @@ main()
533
512
</exercise>
534
513
535
514
<note>
536
-
<p>The function range(start, end, by) will return a range object (an iterator) that allows you to loop from start (inclusive) to end (exclusive) and add the value of by after each execution of the loop.</p>
515
+
<p>The function <c>range(start, end, by)</c> will return a range object (an iterator) that allows you to loop from <c>start</c> (inclusive) to <c>end</c> (exclusive) and add the value of <c>by</c> after each execution of the loop.</p>
<p>What do you think would happen if you deleted lines 6 and 7 in the above code?</p>
623
-
601
+
624
602
<note>
625
603
<p>A loop that never ends is called an infinite loop. A while loop should have some way to end. If you have an infinite loop you may need to refresh the page to stop it.</p>
0 commit comments