0% found this document useful (0 votes)
50 views12 pages

COMP1753 Mock Exam 2

Mock Exam test 2 of COMP1753 Programming Foundation module
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views12 pages

COMP1753 Mock Exam 2

Mock Exam test 2 of COMP1753 Programming Foundation module
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

MOCK EXAM_________________________________________________________

FACULTY OF LIBERAL ARTS & SCIENCES

Campus Maritime Greenwich

School Computing & Mathematical Sciences

Level 4

Academic Stage Undergraduate

TITLE OF PAPER Programming Foundations – MOCK PAPER 2

COURSE CODE COMP1753

Time 1 hour 30 minutes

Answer ALL questions

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.

To submit your answers, go to the COMP1753 Moodle page and


enter your solutions in the “mock exam 2” submission link.

Programming Foundations
COMP1753

Page 1 of 12
MOCK EXAM_________________________________________________________

Answer all questions


1. Which of the following are keywords in Python (choose 2)?

A. more
B. else
C. do
D. or
E. but
[5 marks]

2. Which of the following are legal variable names (choose 2)?

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

A. ____ will not appear


B. ____ will appear 2 times
C. ____ will appear 3 times
D. ____ will appear 4 times
E. ____ will go on printing forever
[5 marks]

Programming Foundations
COMP1753

Page 2 of 12
MOCK EXAM_________________________________________________________

4. The function below is designed to print a list of items. Optionally the


programmer can pass a header string as a second parameter which will get
printed out before the list. Which lines need to be corrected to fix any syntax
errors make the code work correctly (choose 2)?

01 def print_items(items, header=None):


02 """ print out a list of items """
03 if headr != None:
04 print(header)
05 for i in list:
06 print(i)
07 print()

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)?

number = [10, 20, 30, 40]


print(number[1] + number[2])

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_________________________________________________________

7. What value will be printed if print_calc is called (choose 1)?

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]

8. Identify all legal Python operators (choose 2).

A. =!
B. *=
C. -
D. $
E. £

[5 marks]

Programming Foundations
COMP1753

Page 4 of 12
MOCK EXAM_________________________________________________________

9. Identify all correct list declarations (choose 2).

A. symbols = []
B. symbols = "Alpha", "Beta", "Gamma"
C. symbols = ("Alpha", "Beta", "Gamma")
D. symbols = ["Alpha", "Beta", "Gamma"]
E. symbols = ["Alpha"],["Beta"],["Gamma"]
[5 marks]

10. Identify the lines containing a legal Python comment (choose 2)

A. " " is this a comment? " "


B. /** is this a comment? **/
C. """ is this a comment? """
D. " is this a comment?
E. # is this a comment?

[5 marks]

11. What will be printed out if this code is run (choose 1)?

fruit = ["apple", "banana", "onion"]


print(fruit[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_________________________________________________________

The following code is used for questions 12 and 13.

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. *=
*=*=
*=*=*=
*=*=*=*=
*=*=*=*=*=

E. There will be a run-time error


[5 marks]

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.
*=*=
*=*=

E. There will be a run-time error

[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}")

A. There will be a run-time error


B. an_int = 0
C. an_int = 1
D. an_int = 6
E. an_int = 24

[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.

size = int(input("What size shoes? "))


if size < 4 or size > 8:
print("Size " + str(size) + " not available")
return
number = int(input("How many pairs? "))
if number <= 0:
print("Please enter a positive number")
return
cost = 0
if size == 4:
cost = 20
elif size == 5:
cost = 25
else:
cost = 30
cost *= number
if number >= 2: # discount
cost -= 5

print(f"That will be £{cost:.2f}")

15. What size shoes are available (choose 1)?

A. All sizes greater than and including 4


B. Sizes 20, 25 and 30
C. Sizes 4 and 5
D. Sizes 4, 5 and 6
E. Sizes 4, 5, 6, 7 and 8
[5 marks]

16. What is the output if the user chooses 2 pairs of size 5 (choose 1)?

A. That will be £25.00


B. That will be £40.00
C. That will be £45.00
D. That will be £50.00
E. Size 5 not available
[5 marks]

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]

The following code is used for questions 18, 19 and 20.

It is part of a program which interacts with the user to generate passwords.

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_________________________________________________________

18. What statements describe the program's functionality (choose 2)?

A. It runs a loop which generates random passwords, each 10 or 20


characters long
B. It prompts the user for password strength and uses the response to
determine how long and how complex the password is
C. It terminates when the user enters 0 for the password strength
D. It terminates if the user enters a number above 10
E. It uses a mixture of letters, numbers and punctuation for every password

[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]

20. Suppose that


if strength >= 5:
near the middle of the program, is replaced by
elif strength >= 5:
Which of the following strength values would then generate passwords which
include numbers (choose 1)?
A. 5
B. 7
C. 9
D. 11
E. None of them

[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

Your Full Name (please use Block Capitals) : _______________________

Your Student ID (e.g 000123456): _______________________


Please circle all correct answers
1. A B C D E
2. A B C D E
3. A B C D E
4. A B C D E
5. A B C D E
6. A B C D E
7. A B C D E
8. A B C D E
9. A B C D E
10. A B C D E
11. A B C D E
12. A B C D E
13. A B C D E
14. A B C D E
15. A B C D E
16. A B C D E
17. A B C D E
18. A B C D E
19. A B C D E
20. A B C D E

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

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy