Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

PCSE

Total questions: 57

Worksheet time: 43mins

Name
Class
Date
1.

What is the value returned from this code?

print(type(4))

a)

<type 'bool'>

b)

<class 'int'>

c)

<type 'str'>

d)

Undefined

2.

Which line of code inserted in the program will add a random item from the list each time the loop runs?

a)

prize_list = random.choice(rand_item)

b)

rand_item = option_list.random(prize_list)

c)

rand_item = random.choice(option_list)

d)

rand_item = option_list.random()

3.

Which collection structure allows items that are ordered and unchangeable?

a)

Tuple

b)

Dictionary

c)

List

d)

Set

4.

Which of the following code snippets would be the correct way to import everything from a module

a)

Option 1

b)

Option 2

c)

Option 3

d)

Option 4

5.

A developer wants to read a text file but he is unsure if the file exists in the current directory. Suggest a suitable module that would be used to check for the presence of the file in the current working directory.

a)

os module

b)

file module

c)

re module

d)

sys module

6.

Consider the following piece of code. Which of the following is true?

from sklearn.linear_model import LinearRegression

a)

sklearn is a module and kernel_approximation is a package

b)

sklearn and linear_model are both packages

c)

LinearRegression is a module, which comes the linear_model package

d)

linear_model is a module of the sklearn package

7.

The pip command line utility allows the developer to install _______?

a)

Python modules

b)

Invalid

c)

Python libraries

d)

Python packages

8.

Suggest why a program may be broken down into individual functions

a)

Maintainability. Smaller, simpler functions are easier to maintain.

b)

It helps to avoid syntax errors

c)

Debugability. It's easier to debug simple functions than complex ones

d)

Non-Descriptive Naming of Variables

9.

Which code would allocate and initialize a list of 10 integers?

a)

for i in range(11) nlist.append(i)

b)

None of these

c)

nlist = [0,0,0,0,0,0,0,0]

d)

nlist = [0] * 10

10.

Which of the following best describes 're'? 're' (regular expression) provides regular expression matching operations similar to those found in Perl.

a)

an environment

b)

a module

c)

a package

d)

a suite

11.

Please select the correct answer regarding the following code

a)

Both variables contain string objects

b)

Output will be 'Kim'

c)

Output will be True

d)

Output will be False

12.

How many except statements can a try-except block have?

a)

one

b)

more than one

c)

zero

d)

at least one

13.

Which of the following methods allows multiple items from a string to be added as individual elements to an existing list? Use the example below for context

a)

append()

b)

extend()

c)

insert()

d)

pop()

14.

Which of the following best describes the built-in set class?

a)

A mutable, iterable collection able to hold any type

b)

ordered collection, mutable, non-iterable collection able to hold any type

c)

unordered collection, iterable, mutable and has no duplicate elements

d)

An immutable, iterable collection able to hold any type

15.

A data structure that can't be changed after its creation is known as _____?

a)

duck-typed

b)

strongly-typed

c)

immutable

d)

mutable

16.

A programmer tries to run the following code. What error is likely to be raised in this instance?

#Example:

print(int('cat'))

a)

SyntaxError

b)

GrammarError

c)

EOLerror

d)

ValueError

17.

Which of the following shows the correct way to initialize a multidimensional array?

a)

arr = []

b)

arr = ['Jack].extend(['Kan','Ryne','Ema'])

c)

arr = [[]]

d)

arr = [][]

18.

Which of the following modes of file reading would be most appropriate for a program designed to update the contents of a .txt file without making any new deletion to the file.

a)

re

b)

r

c)

w

d)

a

19.

What is the value of the variable 'c' in the following code snippet?

a)

4

b)

1

c)

3

d)

2

20.

Which methods would be used to generate random numbers in Python?

a)

random.uniform()

b)

uniform.random()

c)

random.randint()

d)

random.random()

21.

What is the output of the following code snippet?

a)

'I got a second chance at this!'

b)

The execution will not enter the if-else statement.

c)

'I am not being careful...'

d)

'I am being careful!'

22.

What will happen when the user enters 12?

a)

There will be an error caused by trying to access index 12

b)

The program will print 'Your favorite month is January!'

c)

The program will print 'Your favorite month is !'

d)

The program will print 'Your favorite month is December!'

23.

What is the type of the variable c in the code snippet?

a)

Floating point

b)

This will raise an error.

c)

Integer

d)

Decimal

24.

A programmer accidentally attempts to call a function or use an operator on something of the incorrect type. What error is likely to be raised in this instance?

a)

ValueError

b)

AttributeError

c)

TypeError

d)

NameError

25.

What would be the output of the following code?

a)

['Glass']

b)

['Mug', 'Plate', 'Bowl', 'Saucer']

c)

['Saucer']

d)

['Plate', 'Bowl', 'Saucer']

26.

A programmer wants to match a specific string using a regular expression. What would be most appropriate to match the following string? 'Hello NAME' can be any 4 letter name containing only letters, such as 'Hi Alex', or 'Hi John'

a)

r'Hi \W{4}"

b)

r'Hi \d\d\d\d'

c)

r'hi\w{4}'

d)

r'Hi \w{4}'

27.

A programmer accidentally attempts convert the type of an object and receives the next error: 'int() cannot convert 'dog' into an integer'. What error was likely raised in this instance?

a)

TypeError

b)

ValueError

c)

AttributeError

d)

NameError

28.

What data type would be created by this code?

arr = ('four', 'one', 'seven')

a)

Tuple

b)

List

c)

Set

d)

Dictionary

29.

What is the purpose of the following code?

a)

Trap an invalid integer value

b)

Convert b to a string

c)

Invalid syntax

d)

None of these

30.

Assume you have written your Python code in a separate file named 'myfunctions.py'. Which of the following statements shows the correct syntax for adding it to your new Python script so the code can be used?

a)

import "myfunctions"

b)

using myfunctions

c)

import myfunctions

d)

copy myfunctions

31.

What is the value returned from this code?

print(type(True))

a)

Undefined

b)

<type 'int'>

c)

<class 'bool'>

d)

<type 'str'>

32.

____ is a programming paradigm that provides a means of structuring programs so that properties and behaviors are bundled into individual objects.

a)

Encapsulation

b)

Object-oriented programming

c)

Instantiation

d)

Inheritance

33.

What are Runtime Errors in Python? (Select all that apply)

a)

An error which occurs while loading the script

b)

Errors that occur when you break the rules defined in Python while creating a script

c)

Errors that occur because of misspelled or incorrectly capitalized variable and function names

d)

Errors that show up when the script is attempting to perform operations on data of the wrong type

34.

Which of the following methods allows to insert a specified value on a specified position? Use the example below for context

a)

append()

b)

extend()

c)

pop()

d)

insert()

35.

Which of the following best describes the randint function of the random module. Consider the example below to see the code in context.

x = random.randint(1, 5)

a)

producing between 1 to 5 individual random integers

b)

producing a random float between the values of 1 and 5 (inclusive of 1 and 5)

c)

producing a random integer between 1-5 (inclusive of 1 and 5)

d)

producing a random integer between 1-5 (excluding 1 and 5)

36.

Which of the following statements are true?

a)

Compiled code tends to execute faster than interpreted code

b)

An interpreter translates one statement of the source code at a time into machine code

c)

None of the above

d)

A compiler scans the entire source code file and translate the whole of it into machine code at once

37.

A programmer wants to use various functions and variables that are used to manipulate different parts of the Python runtime environment. Suggest a suitable module that could be used to check for this task.

a)

file module

b)

os module

c)

re module

d)

sys module

38.

Which collection structure allows items that are ordered, changeable, and does not allow duplicate values?

a)

Tuple

b)

Dictionary

c)

Set

d)

List

39.

The open() function opens a file in text format by default. Which mode opens the file in binary format for reading?

a)

'b'

b)

'rb'

c)

'a'

d)

'r'

40.

Which of the following is a collection type that implements a method called 'insert()'?

a)

dictionary

b)

tuple

c)

list

d)

set

41.

What is the value of the variable 'c' in the following code snippet?

a)

11

b)

3

c)

8

d)

10

42.

A programmer has created a class to represent Employees, and each employee has a unique name, role and ID number. The programmer also wants to create a special method to overload the len() method such that every Employee instance will return the seniority of the company. What is best to use for this situation?

a)

An instance attribute

b)

A class attribute

c)

A property decorator

d)

A dunder method

43.

Which collection structure allows items that are ordered and changeable and contain duplicate values?

a)

Dictionary

b)

List

c)

Tuple

d)

Set

44.

Which of the following is a collection type that implements a method called 'keys()'?

a)

list

b)

tuple

c)

dictionary

d)

set

45.

Will this program cause an error? If not, what will the value be of you_can_pass?

a)

False

b)

SyntaxError

c)

ValueError

d)

True

46.

Identify the Python docstring comment.

a)

Comment 3

b)

Comment 4

c)

Comment 2

d)

Comment 1

47.

What is the value of the variable 'c' in the following code snippet?

a)

-5

b)

-3

c)

-2

d)

-4

48.

When creating a text file using the built-in open() function with 'a mode', what will occur if a file is written to a directory which contains a file having the same name?

a)

The file is overwritten

b)

An OS error

c)

The file is appended to, with the original contents saved

d)

A duplicate is created with a modified filename

49.

When defining an object with a class, what function is used to establish values of an instance?

a)

__init__()

b)

Instantiation()

c)

try()

d)

__default__()

50.

Which of the following shows the correct way to initialize a single dimension array?

a)

arr = []

b)

arr = ['Kan', 'Ryne', 'Em']

c)

arr = {}

d)

arr = [][]

51.

What is the value of the variable 'c' in the following code snippet?

a)

7

b)

8

c)

3

d)

15

52.

An operation that modifies a variable without making a copy is known as ...

a)

in-place operation

b)

static typed operation

c)

constant time operation

d)

mutability operation

53.

What is the result of the following if statement?

a)

when j is 10 the result is True

b)

when j is 20 the result is False

c)

when j is 15 the result is False

d)

when j is 15 the result is True

54.

Identify the Python comment.

a)

"""My comment."""

b)

""#Another comment.""

c)

#Some comment.

d)

// Just comment.

55.

What would be the output of the round() function when this code is evaluated?

a)

4

b)

7

c)

6

d)

5

56.

Which of the following best describes the built-in tuple class?

a)

An immutable, iterable collection able to hold any type

b)

A mutable, iterable collection able to hold any type

c)

A mutable, non-iterable collection able to hold any type

d)

A mutable, iterable collection to hold only one specific type

57.

Consider a program which manages its use by more than one user at a time and to even manage multiple requests by the same user without having to have multiple copies of the programming running in the computer. Which of the following words is suitable for describing the previous program.

a)

A chapter

b)

A module callback

c)

Multithreading

d)

A request loop