These questions follow Lists. Every one of them uses the same starting list, so keep it in a file and edit as you go:

marks = [78, 91, 46, 63]

Positions and bounds

  1. What does each print? marks[0], marks[3], marks[-1], len(marks).
  2. What happens when you run print(marks[4]), and why is 4 a reasonable-looking mistake?
  3. Starting from the original list each time, give the list after marks.append(70), then after marks.insert(1, 55), then after marks.remove(46) β€” applied one after the other.

Loops over lists

  1. Write the loop that totals the marks and prints the average to one decimal place.
  2. Write a linear search that reports the position of "Fifteen Dogs" in titles = ["Birdie", "Fifteen Dogs", "Indian Horse"], and prints -1 when the title is not there.
  3. Count how many of weights = [6.5, 3.0, 11.2, 7.0] are above 6.0.
  4. Find the largest value in weights without using max().
  5. Challenge. Build a new list holding only the passing marks (50 or more) from marks, then print how many there are and what they are.

Answers