New Year Special Limited Time Flat 70% Discount offer - Ends in 0d 00h 00m 00s - Coupon code: 70spcl

Python Institute PCAP-31-03 Certified Associate in Python Programming Exam Practice Test

Page: 1 / 15
Total 145 questions

Certified Associate in Python Programming Questions and Answers

Question 1

What is the expected behavior of the following code?

Question # 1

Options:

A.

it outputs 2

B.

the code is erroneous and it will not execute

C.

it outputs 1

D.

it outputs 3

Question 2

What is the expected behavior of the following code?

Question # 2

Options:

A.

it outputs list assignment index out of range

B.

the code is erroneous and it will not execute

C.

it outputs

D.

it outputs error

Question 3

What is the expected output of the following snippet?

Question # 3

Options:

A.

3

B.

1

C.

2

D.

the code is erroneous

Question 4

A property that stores information about a given class's super-classes is named:

Options:

A.

_upper_

B.

_bases_

C.

_ancestors_

D.

_super_

Question 5

The following class hierarchy is given. What is the expected out of the code?

Question # 5

Options:

A.

BB

B.

CC

C.

AA

D.

BC

Question 6

The following class hierarchy is given. What is the expected output of the code?

Question # 6

Options:

A.

BB

B.

CC

C.

AA

D.

BC

Question 7

Assuming that the snippet below has been executed successfully, which of the following expressions will evaluate to True? (Select two answers)

string = 'python' [::2]

string = string[-1] + string[-2]

Options:

A.

string[0] == string[-1]

B.

string is None

C.

len (string] == 3

D.

string[0] == 'o'

Question 8

What is the expected behavior of the following code?

Question # 8

It will:

Options:

A.

print 4321

B.

print

C.

cause a runtime exception

D.

print 1234

Question 9

What is the expected output of the following code if existing_file is the name of a file located inside the working directory?

Question # 9

Options:

A.

1 2

B.

1 2 3

C.

1 3

D.

2 3

Question 10

Assuming that the following inheritance set is in force, which of the following classes are declared properly? (Select two answers)

Question # 10

Options:

A.

class Class_4 (D, A) : pass

B.

class Class_1(C,D): pass

C.

class Class_3(A,C): pass

D.

class Class_2(B,D): pass

Question 11

What is the expected output of the following code?

Question # 11

Options:

A.

True

B.

0

C.

False

D.

None

Question 12

Assuming that the math module has been successfully imported, which of the following expressions evaluate to True? (Select two answers)

Options:

A.

math. hypot (3,4) == math.sqrt (25)

B.

math. hypot (2,5) == math.truec (2.5)

C.

math. hypot (2,5) == math.true (2.5)

D.

math. cell (2,5) == math.floor (2.5)

Question 13

What is the expected behavior of the following code?

Question # 13

Options:

A.

it outputs error

B.

it outputs list assignment index out of range

C.

the code is erroneous and it will not execute

D.

it outputs

Question 14

A file name like this one below says mat: (select three answers)

services. cpython-36.pyc

Options:

A.

the interpreter used to generate the file is version 3.6

B.

it has been produced by CPython

C.

it is the 36th version of the file

D.

the file comes from the services . py source file

Question 15

What is true about Python packages? (Select two answers)

Options:

A.

the sys.path variable is a list of strings

B.

_pycache_is a folder that stores semi-completed Python modules

C.

a package contents can be stored and distributed as an mp3 file

D.

a code designed to initialize a package's state should be placed inside a file named init.py

Question 16

Which of the following lambda definitions are correct? (Select two answers)

Options:

A.

lanbda x, y; return x\\y - x%y

B.

lambda x, y: x//y - x%y

C.

lambda (x, y = x\\y x%y

D.

lambda x, y: (x, y)

Question 17

Which line can be used instead of the comment to cause the snippet to produce the following expected output? (Select two answers)

Expected output:

1 2 3

Code:

Question # 17

Options:

A.

c, b, a = b, a, c

B.

c, b, a = a, c, b

C.

a, b, c = c, a, b

D.

a, b, c = a, b, c

Question 18

Assuming that the following snippet has been successfully executed, which of the equations are True? (Select two answers)

Question # 18

Options:

A.

len(a) == len (b)

B.

b[0] fe- 1 == a[0]

C.

a [0] == b [0]

D.

a[0] + 1 == b[0]

Question 19

Which of the following lines of code will work flawlessly when put independently inside the inc ( ) method in order to make the snippet’s output equal to 3? (Select two answers)

Question # 19

Question # 19

Options:

A.

put (self.prop + vaI)

B.

self.put (self.get ( ) + vaI)

C.

self.put (get ( ) + vaI)

D.

self.put (self.prop + vaI)

Question 20

If you need to serve two different exceptions called Ex1 and Ex2 in one except branch, you can write:

Options:

A.

except Ex1 Ex2:

B.

except (ex1, Ex2):

C.

except Ex1, Ex2:

D.

except Ex1+Ex2:

Question 21

What is true about Python packages? (Select two answers)

Options:

A.

the__name__variable always contains the name of a package

B.

a package is a group of related modules

C.

the pyc extension is used to mark semi-compiled Python packages

D.

a package is a single file whose name ends with the pa extension

Question 22

A Python module named pymod.py contains a variable named pyvar.

Which of the following snippets will let you access the variable? (Select two answers)

Options:

A.

import pyvar from pymod pyvar = 1

B.

from pymod import pyvar = 1

C.

from pymod import pyvar pyvar ()

D.

import pymod pymod.pyvar = 1

Question 23

If you want to access an exception object's components and store them in an object called e, you have to use the following form of exception statement

Options:

A.

except Exception(e):

B.

except e=Exception:

C.

except Exception as e:

D.

such an action is not possible in Python

Question 24

What is the expected behavior of the following code?

x = 8 ** (1/3)

y = 2. if x < 2.3 else 3.

print(y)

Options:

A.

it outputs 2.0

B.

it outputs 2. 5

C.

the code is erroneus and it will not execute

D.

it outputs 3.0

Question 25

Python's built-in function named open () tries to open a file and returns:

Options:

A.

an integer value identifying an opened file

B.

an error code (0 means success)

C.

a stream object

D.

always None

Question 26

What is the expected behavior of the following code?

Question # 26

Options:

A.

it outputs 1

B.

it outputs 0

C.

it raises an exception

D.

it outputs 2

Question 27

What is the expected behavior of the following code?

Question # 27

Options:

A.

it outputs 2

B.

the code is erroneous and it will not execute

C.

it outputs 3

D.

it outputs :

Question 28

What will the value of the i variable be when the following loop finishes its execution?

Question # 28

Options:

A.

10

B.

the variable becomes unavailable

C.

11

D.

9

Question 29

Which of the following snippets will execute without raising any unhandled exceptions? (Select answers)

A)

Question # 29

B)

Question # 29

C)

Question # 29

D)

Question # 29

Options:

A.

Option A

B.

Option B

C.

Option C

D.

Option D

Question 30

Which of the equations are True? (Select two answers)

Options:

A.

chr (ord (x)) = = x

B.

ord (ord (x)) = = x

C.

chr (chr (x)) = = x

D.

ord (chr (x)) = = x

Question 31

What is the expected output of the following code?

Question # 31

Options:

A.

4

B.

16

C.

an exception is raised

D.

1

Question 32

What is true about Object-Oriented Programming in Python? (Select two answers)

Options:

A.

if a real-life object can be described with a set of adjectives, they may reflect a Python object method

B.

the same class can be used many times to build a number of objects

C.

each object of the same class can have a different set of methods

D.

a subclass is usually more specialized than its superclass

Question 33

Can a module run like regular code?

Options:

A.

yes, and it can differentiate its behavior between the regular launch and import

B.

it depends on the Python version

C.

yes, but it cannot differentiate its behavior between the regular launch and import

D.

no. it is not possible; a module can be imported, not run

Question 34

Which of the following expression evaluate to True? (Select two answers)

A)

Question # 34

B)

Question # 34

C)

Question # 34

D)

Question # 34

Options:

A.

Option A

B.

Option B

C.

Option C

D.

Option D

Question 35

What is the expected output of the following code?

Question # 35

Options:

A.

a

B.

an exception is raised

C.

b

D.

c

Question 36

What is the expected output of the following code?

def foo(x,y,z):

return x(y) - x(z)

print{f00(lambda x: x % 2, 2, 1) )

Options:

A.

1

B.

0

C.

-1

D.

an exception is raised

Question 37

If you need a function that does nothing, what would you use instead of XXX? (Select two answers)

def idler ( ):

XXX

Options:

A.

pass

B.

return

C.

exit

D.

None

Question 38

What is the expected behavior of the following code?

Question # 38

Options:

A.

it outputs 'None'

B.

it outputs 3

C.

it raises an exception

D.

it outputs 0

Question 39

Assuming that the code below has been executed successfully, which of the following expressions will always evaluate to True? (Select two answers)

import random

v1 = random. random()

v2 = random. random()

Options:

A.

len(random.sample([1,2,3],2)) > 2

B.

v1 == v2

C.

random.choice([1,2,3]) >=1

D.

v1 >= 1

Question 40

What is the expected behavior of the following code?

Question # 40

It will:

Options:

A.

print 0

B.

cause a runtime exception

C.

prints 3

D.

print an empty line

Question 41

Which of the following expressions evaluate to True? (Select two answers)

Options:

A.

len ('' ' '') == 2

B.

len ( ' ' ' 12

34 ' ' ') == 4

C.

chr (ord('z') - 1 == 'Y'

D.

ord (''0'') - ord (''9'') == 10

Question 42

Which of the following statements are true? (Select two answers)

Options:

A.

Python strings are actually lists

B.

Python strings can be concatenated

C.

Python strings can be sliced like lists

D.

Python strings are mutable

Question 43

What is the expected output of the following snippet?

Question # 43

Options:

A.

abc

B.

The code will cause a runtime exception

C.

ABC

D.

123

Question 44

What is the expected output of the following code if there is no file named non existing_file inside the working directory?

Question # 44

Options:

A.

2 2

B.

1 3

C.

1 2 3

D.

2 2 3

Page: 1 / 15
Total 145 questions