How can one variable store a whole class list?
Using a separate variable for every student quickly becomes difficult to manage.
An array stores several values of the same type under one meaningful name.
An array stores many related values under one identifier. Each value is found using its position, called an index.
Using a separate variable for every student quickly becomes difficult to manage.
An array stores several values of the same type under one meaningful name.
Look at Figure 2. The array name stays the same, but the index changes. The index is the address of one element.
Score[3] means: use the value at position 3. In this array, that value is 81.
Each pigeonhole belongs to the same cabinet, but every slot has its own number.
The cabinet name is the array identifier. The slot number is the index. The item inside is the stored value.
The loop changes the index from 1 to 5. Each pass accesses the next element.
FOR Index โ 1 TO 5 OUTPUT Score[Index] NEXT Index
for index in range(5):
print(score[index])Uses one index.
StudentName[2]
Uses two indexes: row and column.
Score[2,1] means row 2, column 1.
Array questions often provide identifiers such as StudentName[], ScreenTime[] or TeamPoints[]. Use those exact names.
Total โ 0 FOR Index โ 1 TO 50 Total โ Total + Number[Index] NEXT Index OUTPUT Total
This does not identify which element is being added.
The index selects one element during each loop pass.