Big Halloween Sale Limited Time 70% Discount Offer - Ends in 0d 00h 00m 00s - Coupon code: 70percent

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

Demo: 46 questions
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

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

(Select two answers.)

Options:

A.

a == b

B.

b {1} == 4

C.

a is not None

D.

a (2) == 4

Question 3

The__bases__property contains:

Options:

A.

base class locations (addr)

B.

base class objects (class)

C.

base class names (str)

D.

base class ids (int)

Question 4

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 5

How many lines does the following snippet output?

Options:

A.

three

B.

one

C.

two

D.

four

Question 6

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 7

An operator able to perform bitwise shifts is coded as (select two answers)

Options:

A.

- -

B.

++

C.

<<

D.

>>

Question 8

What is the expected behavior of the following code?

Options:

A.

It outputs 3.

B.

It outputs 1.

C.

It outputs 6.

D.

It raises an exception

Question 9

A two-parameter lambda function raising its first parameter to the power of the second parameter should be declared as:

Options:

A.

lambda (x, y) = x ** y

B.

lambda (x, y): x ** y

C.

def lambda (x, y): return x ** y

D.

lambda x, y: x ** y

Question 10

What is true about the following snippet? (Select two answers)

Options:

A.

the code will raise an unhandled exception

B.

the string I feel fine 'will be seen

C.

the string it's nice to see you will be seen

D.

the string what a pity will be seen

Question 11

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?

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 12

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 13

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

Options:

A.

'in not' in 'not'

B.

'in' in 'Thames'

C.

't' . upper ( ) in 'Thames'

D.

'in' in 'in'

Question 14

You are going to read just one character from a stream called s. Which statement would you use?

Options:

A.

ch = read(s, 1)

B.

ch = s. input(1)

C.

ch = input(s, 1)

D.

ch = s. read(l)

Question 15

How many elements will the list2 list contain after execution of the following snippet?

list1 = [False for i in range (1, 10) ]

list2 = list1 [-1:1:-1]

Options:

A.

zero

B.

five

C.

seven

D.

three

Question 16

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 17

What is the expected output of the following code?

Options:

A.

3

B.

5

C.

4

D.

an exception is raised

Question 18

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

Options:

A.

BB

B.

CC

C.

AA

D.

BC

Question 19

What is the expected behavior of the following code?

Options:

A.

it outputs 1

B.

it outputs 2

C.

the code is erroneous and it will not execute

D.

it outputs 3

Question 20

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

string = 'SKY' (:: -1)

string = string (-1)

Options:

A.

string is None

B.

string (0) == string (-1

C.

string (0) == 'Y'

D.

len (string) == 1

Question 21

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

Options:

A.

_upper_

B.

_bases_

C.

_ancestors_

D.

_super_

Question 22

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:

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 23

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

A)

B)

C)

D)

Options:

A.

Option A

B.

Option B

C.

Option C

D.

Option D

Question 24

What is the expected behavior of the following code?

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 25

Assuming that the V variable holds an integer value to 2, which of the following operators should be used instead of OPER to make the expression equal to 1?

V OPER 1 -

Options:

A.

<<<

B.

>>>

C.

>>

D.

<<

Question 26

There is a stream named s open for writing. What option will you select to write a line to the stream''

Options:

A.

s.write("Hello\n")

B.

write(s, "Hello")

C.

s.writeln("Hello")

D.

s.writeline("Hello")

Question 27

Assuming that String is six or more letters long, the following slice

String[1:-2]

is shorter than the original string by:

Options:

A.

four chars

B.

three chars

C.

one char

D.

two chars

Question 28

What is the expected behavior of the following code?

Options:

A.

it outputs -2

B.

it outputs 2. 0

C.

it outputs 0. 0

D.

the code is erroneous and it will not execute

Question 29

What is the expected output of the following snippet?

Options:

A.

True False

B.

True True

C.

False False

D.

False True

Question 30

Which of the following lines of code will work flawlessly when put independently inside the add_new () method in order to make the snippet's output equal to [0, 1, 1] ? (Select two answers)

Options:

A.

put self.store(1])

B.

self put stire(1])

C.

self .put self.get () [-1])

D.

self .put (self.store[1])

Question 31

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 32

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

Options:

A.

\e is an escape sequence used to mark the end of lines

B.

ASCII is synonymous with UTF-8

C.

II in ASCII stands for Information Interchange

D.

a code point is a number assigned to a given character

Question 33

A compiler is a program designed to (select two answers)

Options:

A.

rearrange the source code to make it clearer

B.

check the source code in order to see if its correct

C.

execute the source code

D.

translate the source code into machine code

Question 34

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?

Options:

A.

print (get(self))

B.

print (self.get())

C.

print (get())

D.

print (self.get (val))

Question 35

What can you deduce from the following statement? (Select two answers)

str = open('file.txt', "rt")

Options:

A.

str is a string read in from the file named file.txt

B.

a newlina character translation will be performed during the reads

C.

if file. txt does not exist, it will be created

D.

the opened file cannot be written with the use of the str variable

Question 36

What is the expected behavior of the following snippet?

It will:

Options:

A.

cause a runtime exception

B.

print 1

C.

print 0 , [1]

D.

print [1J

Question 37

What is the expected output of the following snippet?

Options:

A.

3

B.

1

C.

2

D.

the code is erroneous

Question 38

What is the expected behavior of the following code?

It will:

Options:

A.

print 0

B.

cause a runtime exception

C.

prints 3

D.

print an empty line

Question 39

What is the expected behavior of the following code?

Options:

A.

it outputs 1

B.

it outputs 0

C.

it raises an exception

D.

it outputs 2

Question 40

What is the expected output of the following code?

Options:

A.

4

B.

16

C.

an exception is raised

D.

1

Question 41

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 42

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

Options:

A.

isinstance (obj_b,A)

B.

A.VarA == 1

C.

obj_a is obj_aa

D.

B.VarA == 1

Question 43

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 44

What is the expected behavior of the following code?

Options:

A.

it raises an exception

B.

it outputs True

C.

it outputs False

D.

it outputs nothing

Question 45

What is the expected output of the following snippet?

Options:

A.

the code is erroneous

B.

3

C.

7

D.

15

Question 46

Which of the following lines of code will work flawlessly when put independently inside the add_new () method in order to make the snippet's output equal to [0, 1, 21 ? (Select two answers)

Options:

A.

self.queue.append(get_Iast() + 1)

B.

queue.append(self.get last () + 1)

C.

self.queue.append(self.queue[+1]

D.

self.queue.append(self.get last() +1)

Demo: 46 questions
Total 154 questions