# 06 - Tutorial #4+Past Paper Qs -arrays,game

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 name of the array in this program?(1 marks)
```global numbers
#An array/list with 10 spaces each corresponding to a number
numbers=["","","","","","","","","",""]
numbers="A"
print(numbers)```

3. Referring to the question above, what is the output of this program? (1 mark)

4. What is the output from the following program (1 mark)
```global numbers
#An array/list with 10 spaces each corresponding to a number
numbers=["","","","","","","","","",""]
if numbers=="":
print("Empty")
else:
print("Taken")```

5. In the following code, the list called numbers has been declared as 'global'. What does this refer to? (1 mark)
```global numbers
#An array/list with 10 spaces each corresponding to a number
numbers=["","","","","","","","","",""]

def makemove():
player=input("Enter Player Name:")
if numbers[move-1]=="":
freecount()
#In the next line we assign the player name (e.g. A B or C to the place in the array)
numbers[move-1]=player
print(numbers)
freecount()
makemove()
```

6. Assuming this is the whole of the code, Line 10 and 14 of this program will fail to run/execute. Can you explain why? (1 mark)
```global numbers
#An array/list with 10 spaces each corresponding to a number
numbers=["","","","","","","","","",""]

def makemove():
player=input("Enter Player Name:")
if numbers[move-1]=="":
freecount()
#In the next line we assign the player name (e.g. A B or C to the place in the array)
numbers[move-1]=player
print(numbers)
freecount()
makemove()

else:
print("Sorry, that number has been taken")
makemove()```

7. In the above program, a user enters their player name (e.g. A) and then enters the number 15. What is the output? Be specific (1 mark)

8. In the following code, refer to line 8. What is the value of move-1, if the input for move on line 7 is 3? (1 mark)
```global numbers
#An array/list with 10 spaces each corresponding to a number
numbers=["","","","","","","","","",""]

def makemove():
player=input("Enter Player Name:")

makemove()```

9. The array (python language) is 0 index based. If the user entered move=3, and we wanted to store the player's name in the third available place in the list, this would be equivalent to index postion:

10. This function counts up the number of free spaces in the list. What needs to go in line 5? (1 mark)
```def freecount():
free=0
for i in range(len(numbers)):
if numbers[i]=="":
?
print("Remaining count of free numbers:",free)
makemove()```