1. Arrays, in most programming languages, can be defined as a collection of elements of a single (THE SAME) data type, eg. array of int, array of string.
2.
In Python, there is no native array data structure. So, we use Python lists instead of an array.
3. Python has a whole set of built in methods that you can use on lists/arrays. Which of the following is NOT a valid method?
4. Here we have created a 1d array which is just a simple list called 'arr'. What is the output of this program?
arr = [10, 20, 30, 40, 50]
print(arr[0])
print(arr[1])
print(arr[2])
10,10,10
1,2,3
10,20,30 (the first element of the array is 10 which is arr[0])
20,30,10 (the first element o fthe array is 20 which is arr[1])
5. Python programming supports negative indexing of arrays, something that is not available in arrays in most programming languages. The index value of -1 and-2 will output:
6. As you become a professional programmer, finding the length of an array is invaluable. What is the output here?
7. Modification of elements in arrays/lists is possible. What is the output here?
fruits = ["Apple", "Banana", "Mango", "Grapes", "Orange"]
fruits[1] = "Pineapple"
fruits[-1] = "Guava"
print(fruits)
['Apple', 'Pineapple', 'Mango', 'Grapes', 'Guava']
['Guava', 'Pineapple', 'Mango', 'Grapes', 'Guava']
['Apple', 'Banana', 'Mango', 'Grapes', 'Apple']
['Pineapple', 'Pineapple', 'Mango', 'Grapes', 'Guava']
8. A multidimensional array is an _________________________. This means an array holds different arrays inside it.
9. The following code is printing the different lists inside a multidimensional array. Why is the last list in the array not printing?
10. The following code prints the number '3' from the multidimensional array. What would you type to print the number 8?
11. A matrix is a ___________. In real-world tasks youwill often have to store data in a rectangular data table.
12. The following represents a _______ matrix where ___ is the number of rows and ___ is the number of columns.
A = [['Roy',80,75,85,90,95],['John',75,80,75,85,100],['Dave',80,80,80,90,95]]
2 x 6 - 2 - 6
None of the above
6 x 6 - 6 - 6
3 x 6 - 3 - 6
13. In python, matrix is a nested list. A list is created by placing all the items (elements) inside a square bracket [ ], separated by commas.
# a is _____________________?
a = [['Roy',80,75,85,90,95],
['John',75,80,75,85,100],
['Dave',80,80,80,90,95]]
#b is a ______________________?
b= [['Roy',80,75,85,90,95],
['John',75,80,75],
['Dave',80,80,80,90,95]]
a is 2-D matrix with integers
and b is a nested list but not a matrix
a is a matrix and a nested list with strings and b is just a nested loop of strings
a is a nested list but not a matrix and b is a 2-D matrix with integers
None of the above are applicable to 'a' and 'b'
14. Here a is a matrix that contains name and marks of the students. To see all the marks for the student 'Roy' you would use:
a = [['Roy',80,75,85,90,95],
['John',75,80,75,85,100],
['Dave',80,80,80,90,95]]
print(a[0][1])
print(a[0])
print(a[1][2])
print(a[1])
15. In the matrix 'a' how would you output the '100' that belongs to John?
a = [['Roy',80,75,85,90,95],
['John',75,80,75,85,100],
['Dave',80,80,80,90,95]]
print(a[1][1])
print(a[2][5])
print(a[1][5])
print(a[100][3])
16. The following shows the creation of a 3d array protoype for a cinema (the dimensions are floor, row, seat)
17. It is useful to know that in other programming languages you have static and dynamic arrays. A static array has a defined length which does not change
18. A dynamic array does not have a definite size as the program runs. It can grow and shrink as items are added or deleted. Python lists are:
19. An array can be thought of as a ______ data structure and an array of arrays can be seen as a two dimensional array.
20. We can use an array of arrays to represent two-dimensional spaces like chess board made up of different squares. Noughts and crosses would…