COMP1753 Mock Exam 1
COMP1753 Mock Exam 1
Level 4
You may use your log book and a text book during the exam. You may also use a
computer and online Python documentation as reference material.
Programming Foundations
COMP1753
Page 1 of 9
MOCK EXAM_________________________________________________________
A. and
B. do
C. elseif
D. var
E. break
[5 marks]
A. #five_pence_piece
B. five pence piece
C. 5_pence_piece
D. five_pence_piece
E. fivepencepiece
[5 marks]
3. How many times will xx appear if printx is called with the parameter i being
set to 0 (choose 1)?
def printx(i):
while i < 3:
print("xx")
i += 1
return i
Programming Foundations
COMP1753
Page 2 of 9
MOCK EXAM_________________________________________________________
5. What will be printed out when you run the following code (choose 1)?
A. 12
B. "1""2"
C. 23
D. "2""3"
E. There will be a run-time error
[5 marks]
A. +=
B. =+
C. !=
D. +-
E. <>
[5 marks]
A. # This is a comment
B. // This is a comment
C. " This is a comment "
D. """"This is a comment""""
E. / * This is a comment */
[5 marks]
Programming Foundations
COMP1753
Page 3 of 9
MOCK EXAM_________________________________________________________
def f1():
result = f2(4)
print(result)
def f2(par):
if par < 3:
return par
elif par == 3:
return par * 2
else:
return par * 3
A. def func()
B. def = func()
C. def: func()
D. def func():
E. func():
[5 marks]
10. How do you invoke (call) a function named "func" (choose 1)?
A. func()
B. func.invoke()
C. call func()
D. call function func()
E. call.func()
[5 marks]
Programming Foundations
COMP1753
Page 4 of 9
MOCK EXAM_________________________________________________________
11. What will be printed out if this code is run (choose 1)?
[5 marks]
01 n = 4
02 for i in range(1, n+1):
03 output = ""
04 for j in range(1, 6):
05 output += f" {j * i}"
06 print(output)
12. What will be output when the code is run (choose 1)?
A. 1
2 4
3 6 9
4 8 12 16
B. 1 2 3 4
2 4 6 8
3 6 9 12
4 8 12 16
C. 1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
D. 1 2 3 4 5
2 4 6 8 10
3 6 9 12 15
4 8 12 16 20
[5 marks]
Programming Foundations
COMP1753
Page 5 of 9
MOCK EXAM_________________________________________________________
13. Assuming any run-time errors are fixed, the output still has a formatting
problem where the numbers 10 and above take up two spaces, whilst numbers
below 10 take up 1 space. What should be done to fix this and make all the
numbers line up (choose 1)?
14. What will be printed out when you run the following code (choose 1)?
sum = 0
for count in range(3):
sum = sum + 3
print(f"The value of sum = {sum}")
[5 marks]
Programming Foundations
COMP1753
Page 6 of 9
MOCK EXAM_________________________________________________________
The following code is used for questions 15 and 16. It is part of a program which
calculates the cost of tickets.
The user inputs the number and type of tickets that they require and the program
calculates the cost and prints the result.
15. What is the output if the user enters “6” and “Premium” (choose 1)?
[5 marks]
16. What is the output if the user enters “10” and “C” (choose 1)?
[5 marks]
Programming Foundations
COMP1753
Page 7 of 9
MOCK EXAM_________________________________________________________
17. What will be printed out when you run the following code (choose 1)?
n = 2
for i in range(2, 0, -1):
n = n + n
print(f"The value of n = {n}")
[5 marks]
try:
root_path = os.curdir
search = input("Filename? ").lower()
if os.path.isdir(root_path):
my_function(root_path, search)
except OSError as err:
print(err)
print("Stopping, can't access files.")
Programming Foundations
COMP1753
Page 8 of 9
MOCK EXAM_________________________________________________________
[5 marks]
19. What programming techniques are used in this code (choose 2)?
A. Boolean variables
B. Dictionaries
C. Lists
D. Iteration (loops)
E. Sets
[5 marks]
[5 marks]
Programming Foundations
COMP1753
Page 9 of 9