Why is readings[5] out of range with 5 readings?

Grace_42OP

I have exactly five items.

1

Comments 4

Join the discussion

Already have an account? Log in

  1. TomBeckerreplies: 2

    Indexes start at 0, so five items have indexes 0–4. Index 5 would be a sixth item. For "the last one" regardless of length, use a negative index.

    6
      1. ZosiaN

        And for an even number of items there's no single middle. Statistics module's median handles it.

        6
    1. LiamByte

      Stage 3's middle with len(readings) // 2 is a nice touch — for 5 items that's index 2, the real middle.

      0