It is best to use a POGIL approach with the following. In POGIL students work in groups on activities and each member has an assigned role. For more information see https://cspogil.org/Home.
If you work in a group, have only one member of the group fill in the answers on this page. You will be able to share your answers with the group at the bottom of the page.
A list holds items in order and you can get the value at an index, just like you can with strings. You can also use negative indices, just like you can with strings. You can use the slice operator [start:end] with lists to get a new list by copying part of a list, just like you can with strings. The new list will include the item at the start index (inclusive) and all elements up to the end index - 1.
Write a function sum_first_half that takes a list and returns a the sum of just the first half of the items. For example, sum_first_half([1,2,3,4]) should return ``3`` (sum of 1 and 2) and first_half([7,8,9]) should return ``7``.
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.
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.
Drag the blocks from the left and put them in the correct order on the right to define a function total_at_odd_indices that returns the total of the numbers at odd indices in the passed list.
def total_at_odd_indices(alist):
---
def total_at_odd_indices(alist) #paired
---
total = 0
---
for i in range(1,len(alist),2):
---
for i in range(1,len(alist)): #paired
---
total += alist[i]
---
total += i #paired
---
return total
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.
If you worked in a group, you can copy the answers from this page to the other group members. Select the group members below and click the button to share the answers.
The Submit Group button will submit the answer for each each question on this page for each member of your group. It also logs you as the official group submitter.