Weekend Sale 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 154 questions

Certified Associate in Python Programming Questions and Answers

Question 1

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 2

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 3

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 4

What is the expected behavior of the following code?

Question # 4

Options:

A.

Its outputs 321

B.

It raises an exception.

C.

It outputs 6.

D.

It outputs 123.

Question 5

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

Options:

A.

str(1-1) in '012345£739'[:2]

B.

'phd' in 'alpha'

C.

'deb' not in 'abcde' [::-1]

D.

'True' not in 'False'

Question 6

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

Question # 6

Options:

A.

2 2

B.

1 3

C.

1 2 3

D.

2 2 3

Question 7

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 8

What is the expected behavior of the following code?

Question # 8

Options:

A.

It outputs 2

B.

It outputs 0.

C.

It outputs 1.

D.

It raises an exception

Question 9

The following class definition is given. We want the show () method to invoke the get () method, and then output the value the get () method returns. Which of the invocations should be used instead of XXX?

Question # 9

Options:

A.

print (get(self))

B.

print (self.get())

C.

print (get())

D.

print (self.get (val))

Question 10

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 11

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 12

What is the expected behavior of the following code?

Question # 12

Options:

A.

it outputs 0

B.

it outputs 1

C.

it raises an exception

D.

it outputs 2

Question 13

What is true about the __based__attribute in Python?

Options:

A.

It is accessible inside a class and an object.

B.

There is no such property.

C.

it is accessible inside an object

D.

It is accessible inside a class

Question 14

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

Question # 14

Options:

A.

len(a)== len (b)

B.

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

C.

a[0] = b[0]

D.

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

Question 15

What is the expected behavior of the following code?

Question # 15

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 16

What is the expected output of the following code?

Question # 16

Options:

A.

4

B.

16

C.

an exception is raised

D.

1

Question 17

Which of the listed actions can be applied to the following tuple? (Select two answers)

Options:

A.

tup [:]

B.

tup.append (0)

C.

tup [0]

D.

del tup

Question 18

What is the expected output of the following snippet?

Question # 18

Options:

A.

3

B.

1

C.

2

D.

the code is erroneous

Question 19

Assuming that the following code has been executed successfully, select the expressions which evaluate to true.

(Select two answers.)

Question # 19

Options:

A.

a == b

B.

b {1} == 4

C.

a is not None

D.

a (2) == 4

Question 20

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

Options:

A.

lambda X : None

B.

lambda : 3,1415

C.

lambda x : def fun(x): return x

D.

lambda lambda: lambda * lambda

Question 21

What is the expected behavior of the following code?

Question # 21

Options:

A.

it outputs 'None'

B.

it outputs 3

C.

it raises an exception

D.

it outputs 0

Question 22

A method for passing the arguments used by the following snippet is called:

Question # 22

Options:

A.

sequential

B.

named

C.

positional

D.

keyword

Question 23

What is the expected output of the following code if the file named existing_text_file is a non-zero length text file located inside the working directory?

Question # 23

Options:

A.

the length of the first line from the file

B.

-1

C.

the number of lines contained inside the file

D.

the length of the last line from the file

Question 24

Assuming that the code below has been placed inside a file named code.py and executed successfully, which of the following expressions evaluate to True? (Select two answers)

Question # 24

Options:

A.

str(Object) == 'Object'

B.

_name == _main_'

C.

ClassA. _module_ == 'ClassA'

D.

len(ClassB.__bases__) == 1

Question 25

You are going to read 16 bytes from a binary file into a bytearray called data. Which lines would you use? (Select two answers)

Options:

A.

data = bytearray (16) bf.readinto (data)

B.

data = binfile.read (bytearray (16))

C.

bf. readinto (data = bytearray (16))

D.

data = bytearray (binfile.read (16))

Question 26

Is it possible to safely check if a class object has a certain attribute0

Options:

A.

yes, by using the hasattr attribute

B.

yes. by using the hasattr () method

C.

yes, by using the hasattr () function

D.

no, it is not possible

Question 27

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 28

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 29

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

Options:

A.

a code point is a point inside the code when execution stops immediately

B.

an escape sequence can be recognized by the # sign put in front of it.

C.

UTF-8 is one of the ways of representing UNICODE code points.

D.

ASCII is the name of a character coding standard

Question 30

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

Question # 30

Options:

A.

1

B.

0

C.

2

D.

the variable becomes unavailable

Question 31

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

Options:

A.

an escape sequence can be recognized by the / sign put in front of it

B.

II in ASCII stands for Internal Information

C.

ASCII is a subset of UNICODE

D.

a code point is a number assigned to a given character

Question 32

Which of the following words can be used as a variable name? (Select two valid names)

Options:

A.

for

B.

True

C.

true

D.

For

Question 33

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

Question # 33

Options:

A.

BB

B.

CC

C.

AA

D.

BC

Question 34

Assuming that the following piece of code has been executed successfully, which of the expressions evaluate to True? (Choose two.)

Question # 34

Options:

A.

isinstance (obj_b,A)

B.

A.VarA == 1

C.

obj_a is obj_aa

D.

B.VarA == 1

Question 35

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 36

What is the expected behavior of the following code?

Question # 36

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 37

Files with the suffix .pyc contain:

Options:

A.

Python 4 source code

B.

backups

C.

temporary data

D.

semi-compiled Python code

Question 38

What is the expected behavior of the following snippet?

Question # 38

It will:

Options:

A.

cause a runtime exception

B.

print 1

C.

print 0 , [1]

D.

print [1J

Question 39

What is the expected behavior of the following code?

Question # 39

It will:

Options:

A.

print 0

B.

cause a runtime exception

C.

prints 3

D.

print an empty line

Question 40

Executing the following snippet

Question # 40

will cause the dct:

Options:

A.

to hold two keys named ‘pi’ linked to 3.14 and 3.1415 respectively

B.

to hold two key named ‘pi’ linked to 3.14 and 3.1415

C.

to hold one key named ‘pi’ linked to 3.1415

D.

to hold two keys named ‘pi’ linked to 3.1415

Question 41

What is the expected output of the following code?

Question # 41

Options:

A.

3

B.

5

C.

4

D.

an exception is raised

Question 42

What is the expected output of the following code?

Question # 42

Options:

A.

21

B.

2

C.

3

D.

12

Question 43

Assuming that the following code has been executed successfully, selected the expression which evaluate to True (Select two answers)

Question # 43

Options:

A.

a ( ) == 4

B.

a is not None

C.

b ( ) == 4

D.

a ! = b

Question 44

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

Question # 44

Options:

A.

is instance(obj_b,C)

B.

C._C__VarA == 2

C.

has atr (B, 'get')

D.

obj_c.get() == 2

Question 45

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 46

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 # 46

Question # 46

Options:

A.

put (self.prop + vaI)

B.

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

C.

self.put (get ( ) + vaI)

D.

self.put (self.prop + vaI)

Page: 1 / 15
Total 154 questions