COMP1753 Mock Exam 2
COMP1753 Mock Exam 2
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 12
MOCK EXAM_________________________________________________________
A. more
B. else
C. do
D. or
E. but
[5 marks]
A. 2a_list
B. a_list2
C. to_a_list
D. #a_list
E. a list
[5 marks]
3. How many times will ____ appear if lines is called with the parameter arg
being set to 7 (choose 1)?
def lines(arg):
while arg <= 10:
print("____")
arg += 1
Programming Foundations
COMP1753
Page 2 of 12
MOCK EXAM_________________________________________________________
A. Line 02
B. Line 03
C. Line 04
D. Line 05
E. Line 06
[5 marks]
5. What will be printed out when you run the following code (choose 1)?
A. 30
B. 1020
C. 50
D. 2030
E. There will be a run-time error
[5 marks]
6. Assuming bool1 is set to True , bool2 is set to False, and bool3 is set
to False, which of the following expressions evaluate to True (choose 2):
A. bool1 and bool2
B. bool2 or not bool3
C. bool2 and not bool3
D. bool1 and bool2 and bool3
E. bool1 or bool2 or bool3
[5 marks]
Programming Foundations
COMP1753
Page 3 of 12
MOCK EXAM_________________________________________________________
def print_calc():
an_int = calculate(5)
print(an_int)
def calculate(arg):
if arg >= 4:
return arg * 2
elif arg <= 5:
return arg * 3
else:
return arg * 4
A. 5
B. 10
C. 15
D. 20
E. There will be a run-time error
[5 marks]
A. =!
B. *=
C. -
D. $
E. £
[5 marks]
Programming Foundations
COMP1753
Page 4 of 12
MOCK EXAM_________________________________________________________
A. symbols = []
B. symbols = "Alpha", "Beta", "Gamma"
C. symbols = ("Alpha", "Beta", "Gamma")
D. symbols = ["Alpha", "Beta", "Gamma"]
E. symbols = ["Alpha"],["Beta"],["Gamma"]
[5 marks]
[5 marks]
11. What will be printed out if this code is run (choose 1)?
A. apple
B. "apple"
C. banana
D. "banana"
E. There will be a run-time error because onion is not a fruit
[5 marks]
Programming Foundations
COMP1753
Page 5 of 12
MOCK EXAM_________________________________________________________
01 n = 5
02 output = ""
03 for i in range(n):
04 for j in range(i+1):
05 output += "*"
06 output += "="
07 output += "\n"
08 print(output)
12. What will be output when the code is run (choose 1)?
A. *=
**==
***===
****====
*****=====
B. *=
*=*=
*=*=*=
*=*=*=*=
*=*=*=*=*=
C. *=*=*=*=*=
*=*=*=*=*=
*=*=*=*=*=
*=*=*=*=*=
*=*=*=*=*=
D. *=
*=*=
*=*=*=
*=*=*=*=
*=*=*=*=*=
Programming Foundations
COMP1753
Page 6 of 12
MOCK EXAM_________________________________________________________
13. If line 07 is deleted and n is set to 2, what will be output when the code is run
(choose 1)?
A.
**==
B.
***===
C.
*=*=*=
D.
*=*=
*=*=
[5 marks]
14. What will be printed out when you run the following code (choose 1)?
an_int = 1
for i in range(5):
an_int = an_int * i
print(f"an_int = {an_int}")
[5 marks]
Programming Foundations
COMP1753
Page 7 of 12
MOCK EXAM_________________________________________________________
The following code is used for questions 15 and 16. It is part of a program which
calculates the cost of pairs of shoes.
The user inputs the size and number of pairs that they want and the program calculates
the cost and prints the result.
16. What is the output if the user chooses 2 pairs of size 5 (choose 1)?
Programming Foundations
COMP1753
Page 8 of 12
MOCK EXAM_________________________________________________________
17. What will be printed out when you run the following code (choose 1)?
n = 2
for i in range(2):
n = n * n
print(f"The value of n = {n}")
A. The value of n = 2
B. The value of n = 4
C. The value of n = 8
D. The value of n = 16
E. The value of n = 32
[5 marks]
while True:
strength = int(input("Strength [0 to terminate]? "))
if strength == 0:
break
if strength > 10:
length = 20
else:
length = strength*2
letters = "abcdefghijklmnopqrstuvwxyz"
characters = letters
if strength >= 2:
characters += letters.upper()
if strength >= 5:
characters += "0123456789"
if strength >= 7:
characters += punctuation
password = ""
for i in range(length):
r = randint(0, len(characters)-1)
password += characters[r]
print(f"Your password is {password}")
Programming Foundations
COMP1753
Page 9 of 12
MOCK EXAM_________________________________________________________
[5 marks]
19. If the program generates the password "wgWKjk", what strength did the user
choose (choose 1)?
A. 1
B. 2
C. 3
D. 4
E. 5
[5 marks]
[5 marks]
Programming Foundations
COMP1753
Page 10 of 12
MOCK EXAM_________________________________________________________
Programming Foundations
COMP1753
Page 11 of 12
MOCK EXAM_________________________________________________________
Answer Sheet
TITLE OF PAPER COMP1753 Programming Foundations
Make sure you submit your answers to the online system too, or you
will FAIL THE EXAM. See the front page of the exam for details.
Programming Foundations
COMP1753
Page 12 of 12