# 27 - Coding Challenge #5 and Past Paper Simulation

1. Work through the following presentation that takes you through 2d arrays, for loops and a practice exam paper question. Select 'Yes' when done. (1 mark)

Yes

No

2. The following code shows a 1d array (list in Python). What is the output of this code? (1 mark)
```weapons1d=["gun","knife","love","truth","crossbow"]
print(weapons1d[3])
```

3. What is the output of this code? (1 mark)
```weapons1d=["gun","knife","love","truth","crossbow"]
print(weapons1d[0])
```

4. The following code shows a 2d array and a print statement. What is the output of this code? (1 mark)
```weapons2d=[["gun","knife","AK47"],["Adam","Eve","Cain"]]
print(weapons2d[1])```

It will print the contents of the second list (that is list 1) which is Adam,Eve,Cain

Out of range error

5. What is the output of this code? (1 mark)
```weapons2d=[["gun","knife","AK47"],["Adam","Eve","Cain"]]
print(weapons2d[0][1])```

6. What is the output of this code? (1 mark)
```weapons2d=[["gun","knife","AK47"],["Adam","Eve","Cain"]]
print(weapons2d[2][1])```

7. What is the output of this code? (1 mark)
```weapons2d=[["gun","knife","AK47"],["Adam","Eve","Cain"]]
weapons2d[0][1]="mercy"
print(weapons2d[1][2])```

8. In the above code, what is happening on line 2? (1 mark)

9. In the following code, on line 2, what is the value of len(weapons2d)? (1 mark)
```weapons2d=[["gun","knife","AK47"],["Adam","Eve","Cain"]]
for i in range(len(weapons2d)):
for j in range(len(weapons2d[0])):
print(weapons2d[i][j])```

10. In the above code, on line 3, what is the value of len(weapons2d[0]) ? (1 mark)

11. Analyse the following code. What line do you need to change, and what do you need to change it to, in order to produce the desired output? (2 marks)
```weapons2d=[["gun","knife","AK47"],["Adam","Eve","Cain"]]
for i in range(1):
for j in range(2):
print("This player:",weapons2d[1][j],"has:",weapons2d[0][j])

#Desired output is below
"""
`mylist=[2,7,24,1,7,9,12,5]`