CSC1015F 2023 Test1
CSC1015F 2023 Test1
Theory Test 1
Marks : 25
Time : 50 minutes
Instructions:
a) Answer all questions.
b) Write your answers in PEN in the spaces provided.
c) You may use a calculator .
Question 1 (1 point)
Which of the following is NOT a property of an algorithm?
a) It can only be used once
b) There exists an algorithm for most well-defined problems
c) It may not run forever
d) It can be executed by any machine
^
____________________________________________
Question 2 (1 point)
Which of the following is an example of a program?
a) The setup manual for your new Laptop.
b) The algorithm to drive a car.
c) Wing 101
d) Direction to your house.
C
____________________________________________
Question 3 (1 point)
Question 3 options:
A is a set of instructions given to a computer, written in
a precise language.
______________________________
program
Question 4 (1 point)
a) ______
1
b) ______
3
2
c) _______
Question 5 (1 point)
___________________________________
average
Basics of Programming
Question 6 (1 point)
Question 6 options:
What is the output of the following Python program:
a = "front"
b = 'back'
print(b, 2, a, sep='-', end='!')
_______________________________
back-2- front!
Question 7 (1 point)
ans = 42
print("The answer to everything is:", ans)
a) expression, function, assignment
b) function, assignment, comment
c) parameters, floating point number, variable
d) string literal, comment, parameters
e) variable, numeric literal, string literal
____________________________________________
Question 8 (1 point)
3 ** 2 // 3 % 4
____________________________
3
Question 9 (1 point)
What line of code is missing from the following Python
program:
num = 9
print("The square root of", num, "is", math.sqrt(num))
import math
_______________________________
Question 10 (1 point)
A
____________________________________________
Selection
Question 11 (1 point)
A
____________________________________________
Question 12 (1 point)
A
____________________________________________
Question 13 (1 point)
The following program sorts three numbers in descending
order. What is the MISSING LINE?
if a > b:
if c > a:
print("c > a > b")
else:
# MISSING LINE
print("a > b > c")
else:
print("a > c > b")
else:
if c > b:
print("c > b > a")
else:
if a > c:
print("b > a > c")
else:
print ("b > c > a")
a) if a > b:
b) if b > a:
c) if b > c:
d) if a > c:
e) if c > b:
___________________________
C
Question 14 (1 point)
The ________ clause is an optional part of the if statement that
is used to decide what to do if the condition is not met.
_________________________
else
Question 15 (1 point)
What is the value of the following boolean expression?
T f F F
(5<10 or 2<1) and (10>20 or not 1>2)
a) False
b) True
c) and
d) or
e) None
________________________
B
Iteration
Question 16 (1 point)
What is the output of the following Python code?
string = "Python is awesome"
count = 0
for letter in string:
if letter == "o":
count += 1
elif letter == "a":
continue
else:
print(letter)
print(count)
a) P, y, t, h, n, i, s, w, e, s, o, m, e, 2
b) P, y, t, h, n, i, s, a, w, e, s, m, e, 2
c) P, y, t, h, n, i, s, w, e, s, m, e, 2
d) P, y, t, h, n, i, s, w, e, s, m, e, 4
e) P, y, t, h, n, i, s, w, e, s, o, m, e, 4
c
____________________________________________
Question 17 (1 point)
Which of the following statements about the range() function in Python
is false?
a) The range() function can only generate sequences in ascending order.
b) The range() function can be used to generate an empty sequence.
c) The range() function can be used to generate a sequence of numbers
between a start and end value.
d) It is used to iterate over a sequence of elements in reverse order.
e) It returns a tuple containing both the index and the value of each element in an iterable.
A
____________________________________________
Question 18 (1 point)
What is the difference between a for loop and a while loop in
Python?
a) A for loop is used for iterating over a sequence of elements, while a while loop is used for
executing code repeatedly as long as a specified condition is true.
b) A for loop is used for iterating over a sequence of elements and also supports the use of the
range() function, while a while loop is used for executing code repeatedly as long as a
specified condition is true.
c) A while loop is used for iterating over a sequence of elements and also supports the use of
the range() function, while a for loop is used for executing code repeatedly as long as a
specified condition is true.
d) A for loop and a while loop are exactly the same and can be used interchangeably.
e) A for loop is used for executing code repeatedly as long as a specified condition is true,
while a while loop is used for iterating over a sequence of elements.
A
____________________________________________
Question 19 (1 point)
What is the difference between the following for loop and while
loop code snippets in Python?
# for loop
for i in range(5):
print(i)
# while loop
i=0
while i < 5:
print(i)
i += 1
a) The for loop and the while loop have the same speed.
b) The for loop executes the code block once for each element in a sequence, while the while
loop executes the code block repeatedly as long as a specified condition is true.
c) The while loop executes the code block once for each element in a sequence, while the for
loop executes the code block repeatedly as long as a specified condition is true.
d) The for loop is faster than the while loop.
e) The while loop is faster than the for loop.
B
____________________________________________
Question 20 (1 point)
The following code prints "Yes" at the end of the execution
when, and only when:
if result:
print("Yes")
else:
print("No")
a) num is an even number
b) num is a decimal number
c) num is a negative number
d) num is an odd number
e) num is a prime number
E
____________________________________________
Strings
Question 21 (1 point)
Question 21 options:
What is the function you would use to remove all capital letters
from a string. Give just the function, not the invocation, as
follows: len()
lower ()
____________________________________________
Question 22 (1 point)
Write a line of Python code to extract the word "Cruel" from the
string below using reverse indexing:
Str [7:-123
____________________________________________
Question 23 (1 point)
What is the output of the following code?
B
____________________________________________
Question 24 (1 point)
What is the output of the following code?
s1="CSC"
s2="1015F"
s3="2023"
____________________________________________
Question 25 (1 point)
____________________________________________