0% found this document useful (0 votes)
17 views4 pages

Multidimensional Arrays Explained

A multidimensional array can store arrays within its elements, with each item having multiple indexes. For example, a two-dimensional array called examResults stores the test scores of 3 students in 4 subjects, with the scores accessed via two indexes like examResults[1,2] = 47. A teacher could store student surnames and test scores in a two-dimensional array called results with the format results[['smith',69],['jakson',90]], and then print the names and scores of students who scored 50 or over by iterating through the results array and checking if the second element at each index is greater than or equal to 50.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views4 pages

Multidimensional Arrays Explained

A multidimensional array can store arrays within its elements, with each item having multiple indexes. For example, a two-dimensional array called examResults stores the test scores of 3 students in 4 subjects, with the scores accessed via two indexes like examResults[1,2] = 47. A teacher could store student surnames and test scores in a two-dimensional array called results with the format results[['smith',69],['jakson',90]], and then print the names and scores of students who scored 50 or over by iterating through the results array and checking if the second element at each index is greater than or equal to 50.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

MULTIDIMENTIONAL ARRYS

A multidimensional Array is an ‘array of arrays’; which each item at an


index is another array.
Ex : single array
Cars=[‘ford’, ’Mercedes’, ‘Toyota’, ‘BMW’, ‘Audi’]
Ex: Two Dimensional Array examResults
Array declared as array[3,4]
0 1 2 3
0 80 59 34 89
1 31 11 47 64
2 29 56 13 91

• Each item of data has two indexes.


• examResults[1,2]=47
• Array for the Table
Scores=[[80,59,34,89],[31,11,47,64],[29,56,13,91]]

Ex1. A teacher has stored the surnames and test scores of a class
of students in a two-dimentional array. Eg
results[[‘smith’,’69’],[‘jakson’,’90’]].etc.create a program that
would print out the names and test scores of all the students who
have scored 50 or over in test.

results=[['smith',69],['jakson',90],['Dubois',30]]
for index in range(0, len(results)):
if results[index][1] >=50:
print(results[index][0] +” “ + str(results[index][1]))
Activity 17

You might also like