2. RUNNER EXAMPLE
⢠Consider a race with 24 runners
⢠Data stored for each runner:
⢠name (string)
⢠bib number (integer)
⢠elite (Boolean)
3. RUNNER EXAMPLE
⢠The data would look like:
etc.
Name Bib Number Elite
John McGrain 1014 False
Akila Sinha 1818 True
Steven Lowe 1374 True
Kyle McNaught 1450 False
4. RUNNER EXAMPLE
⢠We can store this data using three parallel arrays:
name[]
bib_number[]
elite[]
5. RUNNER EXAMPLE
⢠We can initialise the 3 parallel arrays in Python as follows:
name = ['' for x in range (24)]
bib_number = [0 for x in range (24)]
elite = [False for x in range (24)]
Note this will initialise:
⢠all names to empty string
⢠all bib_numbers to 0
⢠all elite values to False
6. RUNNER EXAMPLE
⢠We can set the value of individual array items as follows:
name[0] = âJohn McGrainâ
bib_number[0] = 1014
elite[0] = False
7. RUNNER EXAMPLE
⢠We can set the value of individual array items as follows:
name[0] = âJohn McGrainâ
bib_number[0] = 1014
elite[0] = False
name[1] = âAkila Sinhaâ
bib_number[1] = 1
elite[1] = True
8. RUNNER EXAMPLE
⢠In this example the values are being hard coded into the parallel arrays.
⢠Itâs more likely we would either have the user input the values into the
program and then assign the parallel arrays
or
⢠Read the values from a file into the parallel arrays
9. RUNNER EXAMPLE
⢠Once the arrays have been initialised with values we can get details
about individual runners. For example, Kyle McNaught is the 4th runner
in the arrays so we can get his details using index 3:
print(name[3]) -> Kyle McNaught
print(bib_number[3]) -> 1450
print(elite[3]) -> False