Online worksheet ยท 2 of 4

An index identifies a position - Online practice 2

Read the information, then answer the questions. An adult may read the instructions aloud. Show your working where asked.

Read before answering

Python list: scores = [8,3,7,5]. Non-negative indices start at 0 and must be less than len(scores). The length counts items, not the last index. A separate empty list has length zero and must not be assumed to contain a first item.

Worksheet preview

  1. For [8,3,7,5], give scores[2], len(scores), and the final valid non-negative index.
  2. What would scores[len(scores)] do for this four-item list?
  3. How should code change before reading the first score if this list may become empty?

This exercise is included in the free preview. Register free to complete it and download the preview PDFs. No payment is required.

Register free

Already registered? Sign in