# 25 - Coding Challenge #3 & Past Paper Simulation

1. Please work through the following presentation which takes you through solving a programming challenge (using for loops and 2d arrays (lists) step by step. Select 'True' when done. (1 mark)

TRUE

FALSE

2. What is the output of the following code? (1 mark)
```usernamesandpasswords = [["marvR","open123"],["benjR","pass123"]]
```

3. What is the output of the following code? (1 mark)
```usernamesandpasswords = [["marvR","open123"],["benjR","pass123"]]

4. What is the output of the following code? (1 mark)
```usernamesandpasswords = [["marvR","open123"],["benjR","pass123"]]

5. What code do you need to write on the next line to ensure that the output is benjR?. Refer to the previous examples and write your answer in that format (python) (1 mark)
`usernamesandpasswords = [["marvR","open123"],["benjR","pass123"]]`

6. In a 2d array you require two index numbers to access elements in the array. Using a loop (iteration) would also require two index numbers. (1 mark)

TRUE

FALSE

7. What will the following code output? (1 mark)
```usernamesandpasswords = [["marvR","open123"],["benjR","pass123"]]
for i in range(2):
for j in range(2):
```

8. In the following code you will note that a username and password has been added to the 2d list. Will they be printed? (1 mark)
```usernamesandpasswords = [["marvR","open123"],["benjR","pass123"],["john","john123"]]
for i in range(2):
for j in range(2):
```

9. Line 3 has been changed to for j in range(3) instead of in range(2). Will this print every element in the array? Why or why not? (2 marks)

10. Instead of specifying a number in for i in range(2) you could find out the length of the list, so that if the list grows, the number would always be right. What is the output of this code? (1 mark)
```usernamesandpasswords = [["marvR","open123"],["benjR","pass123"],["john","john123"]]

11. This code will print the first three elements on the list and then produce an error. On which line is the error? (1 mark)
```usernamesandpasswords = [["marvR","open123"],["benjR","pass123"],["john","john123"]]
```

12. Analyse the code below. len(usernamesandpasswords)-1 is essentially the same,given the current elements in the list, as writing what number? (1 mark)
```usernamesandpasswords = [["marvR","open123"],["benjR","pass123"],["john","john123"]]
for i in range(len(usernamesandpasswords)):#this is the outer loop which iterates through the different lists (in this case there are 3 lists)
for j in range(len(usernamesandpasswords)-1): #this is the inner loop which iterates through the different elements in each list, in this case there are 2 elements
```

13. The double loop shown in the code above is also called: (1 mark)

14. On what line does the programming construct SELECTION begin in this program? (1 mark)
```usernamesandpasswords = [["marvR","open123"],["benjR","pass123"]]
found = False
while found == False: