Introduction to Programming with Python
Choose the correct answer.
Question 1
Which ONE (1) of the following is not a high-level programming language?
A Python
B [Link]
C Binary
D Java
Question 2
Select the output from this program:
value1 = 100
while(value1 > 90):
print(value1 + 1)
value1 = value1 - 2
A 101 99 97 95 93
B 100 98 96 94 92
C 92 94 96 98 100
D 93 95 97 99 101
Question 3
Select the program that performs an existence check.
A choice = input()
if(len(choice) > 20):
print("Invalid")
B choice = input()
if(choice < 3):
print("Invalid")
C choice = input()
if(choice <> ""):
print("Invalid")
D choice = input()
if(choice <> "yes" and choice <> "no"):
print("Invalid")
Question 4
Select the commands used for exception handling in Python.
A try:
except:
B try:
catch:
C test:
except:
D test:
catch:
Question 5
Select the example of a logic error.
A Spelling a key word incorrectly
B Using addition instead of multiplication in a calculation
C Attempting to multiply a string with an integer
D Reading from a text file that does not exist
Question 6
Which ONE (1) of the following is a definition of the implementation stage of the software
development lifecycle?
A Writing the program code
B Installing the program in the final place to be used
C Creating a flowchart for part of the system
D Making sure the program meets requirements
Question 7
Select the output from this Python program:
theList = [1,2,3,4,5]
print(theList[1])
A1
B2
C3
D4
-Question 8
Select the content of
from collections import Counter
theData = [5,5,6,8,4,5,1,2,3,6,5,9,6,3,2,5]
counterObject = Counter(theData)
print(counterObject)
A theData([5,5,6,8,4,5,1,2,3,6,5,9,6,3,2,5])
B theData = ({5: 5, 6: 3, 2: 2, 3: 2, 8: 1, 4: 1, 1: 1, 9:
1})
C Counter({5: 5, 6: 3, 2: 2, 3: 2, 8: 1, 4: 1, 1: 1, 9: 1})
D Counter = [1,2,2,3,3,4,5,5,5,5,5,6,6,6,8,9]
Question 9
Select the contents of theList after this program has run:
theList = [1, 5, 1, 2, 3, 6, 5, 8, 9, 6, 3]
for number in theList:
if number >4:
[Link]()
print(theList)
A [1, 1, 2, 3, 3]
B [3, 6, 5, 8, 9, 6, 3]
C [1, 5, 1, 2, 3, 6, 5]
D [1, 1, 3, 5, 9, 3]
Question 10
Which ONE (1) of the following describes the purpose of a variable?
A To store a set of values under one identifier that can be changed whilst the program
is running
B To store a single value that cannot be changed whilst the program is running
C To store a single value that can be changed whilst the program is running.
D To store a set of values under one identifier that cannot be changed whilst the
program is running
Question 11
Select the object-oriented program that creates a class and has the correct syntax for the
constructor.
A class animal():
def __create__(self):
animalType = "horse"
B class animal():
def constructor(self):
animalType = "horse"
C class animal():
def __init__(self):
animalType = "horse"
D class animal():
def new():
animalType = "horse"
Question 12
Select the argument from this program:
def myFunction(theNumber):
newNumber = theNumber – 10
return newNumber
value = int(input())
value = myFunction(value)
print(value)
A value B myFunction
C theNumber D newNumber
Question 13
Select the definition of an object in object-oriented programming (OOP)
A A template
B An instance of a class
C A subroutine
D A value
Question 14
Select the output from this Python program:
first = 10
second = 20
if first >= second:
print(first + second)
else:
print(first * 10)
A 10 B 20
C 30 D 100
Question 15
Which ONE(1) of these constructs is a bounded loop.
A if B for
C repeat D while