Summer Special Limited Time 65% Discount Offer - Ends in 0d 00h 00m 00s - Coupon code: myex65

Home > Python Institute > PCAP > PCAP-31-03

PCAP-31-03 Certified Associate in Python Programming Question and Answers

Question # 4

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

String[1:-2]

is shorter than the original string by:

A.

four chars

B.

three chars

C.

one char

D.

two chars

Full Access
Question # 5

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

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

Full Access
Question # 6

What is the expected output of the following snippet?

A.

abc

B.

The code will cause a runtime exception

C.

ABC

D.

123

Full Access
Question # 7

Which of the following invocations are valid? (Select two answers)

A.

sorted ("python'')

B.

"python" .sort ( )

C.

sort" ("python")

D.

"python' ,find (" ")

Full Access
Question # 8

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

A.

'in not' in 'not'

B.

'in' in 'Thames'

C.

't' . upper ( ) in 'Thames'

D.

'in' in 'in'

Full Access
Question # 9

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

A.

BB

B.

CC

C.

AA

D.

BC

Full Access
Question # 10

What is true about the __based__attribute in Python?

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

Full Access
Question # 11

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

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

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

Full Access
Question # 12

What is the expected out of the following code of the file named zero_length_existing_file is a zero-length file located inside the working directory?

A.

0

B.

-1

C.

an errno value corresponding to file not found

D.

2

Full Access
Question # 13

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

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)

Full Access
Question # 14

What is the expected output of the following code?

A.

3

B.

5

C.

4

D.

an exception is raised

Full Access
Question # 15

What is the expected behavior of the following code?

A.

It outputs 2

B.

It outputs 0.

C.

It outputs 1.

D.

It raises an exception

Full Access
Question # 16

A variable stored separately in every object is called:

A.

there are no such variables, all variables are shared among objects

B.

a class variable

C.

an object variable

D.

an instance variable

Full Access
Question # 17

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

A.

len(a)== len (b)

B.

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

C.

a[0] = b[0]

D.

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

Full Access
Question # 18

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

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

Full Access
Question # 19

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

A.

121 +1 == int ('1' + 2 * '2')

B.

float ('3.14') == str('3.'+'14')

C.

'xyz'.lower() 'XY'

D.

'8' + '8' !=2 * '8'

Full Access
Question # 20

What is the expected output of the following code?

A.

a

B.

an exception is raised

C.

b

D.

c

Full Access
Question # 21

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

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

Full Access
Question # 22

What can you do if you don't like a long package path tike this one0 import alpha.beta.gamma.delta.epsiIon.zeta

A.

you can make an alias for the name using the a 1 i a s keyword

B.

nothing; you need to come to terms with it

C.

you can shorten it to alpha. zeta and Python will find the proper connection

D.

you can make an alias for the name using die as keyword

Full Access
Question # 23

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:

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

Full Access
Question # 24

What is the expected behavior of the following snippet?

It will:

A.

cause a runtime exception

B.

print 1

C.

print 0 , [1]

D.

print [1J

Full Access
Question # 25

What is the expected behavior of the following code?

It will

A.

print 2 1

B.

print 1 2

C.

cause a runtime exception

D.

print

Full Access
Question # 26

Can a module run like regular code?

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

Full Access
Question # 27

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

A)

B)

C)

D)

A.

Option A

B.

Option B

C.

Option C

D.

Option D

Full Access
Question # 28

What is the expected output of the following code?

A.

2

B.

3

C.

4

D.

an exception is raised

Full Access
Question # 29

Which of the following invocations are valid? (Select two answers)

A.

rfind("python","r")

B.

sorted("python")

C.

"python".sort ()

D.

"python".index("th")

Full Access
Question # 30

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

A.

lambda X : None

B.

lambda : 3,1415

C.

lambda x : def fun(x): return x

D.

lambda lambda: lambda * lambda

Full Access
Question # 31

What is the expected behavior of the following code?

A.

it raises an exception

B.

it outputs True

C.

it outputs False

D.

it outputs nothing

Full Access
Question # 32

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

A.

closing an open file is performed by the closefile ( ) function

B.

the second open ( ) argument describes the open mode and defaults to ‘w’

C.

if open ( ) ‘s second argument is ‘r’ the file must exist or open will fail

D.

if open ( )’s second argument is ‘w’ and the invocation succeeds, the previous file’s content is lost

Full Access
Question # 33

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

A.

len('\'•) == 1

B.

len("""

""") == o

C.

chr(ordCA') + 1) == 'B'

D.

ord("Z") - ord("z") -- ord("0")

Full Access
Question # 34

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

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

Full Access
Question # 35

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

A)

B)

C)

D)

A.

Option A

B.

Option B

C.

Option C

D.

Option D

Full Access
Question # 36

What is the expected behavior of the following code?

A.

it outputs False

B.

it outputs True

C.

it raises an exception

D.

it outputs nothing

Full Access
Question # 37

What is the expected behavior of the following code?

It will:

A.

print 4321

B.

print

C.

cause a runtime exception

D.

print 1234

Full Access
Question # 38

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

A.

lists may not be stored inside tuples

B.

tuples may be stored inside lists

C.

tuples may not be stored inside tuples

D.

lists may be stored inside lists

Full Access
Question # 39

What is a true about python class constructors? (Select two answers)

A.

the constructor must have at least one parameter

B.

the constructor must return a value other than None

C.

the constructor is a method named_init_

D.

there can the more than one constructor in a Python class.

Full Access
Question # 40

What is the expected behavior of the following code?

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

Full Access
Question # 41

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

A.

tup [:]

B.

tup.append (0)

C.

tup [0]

D.

del tup

Full Access
Question # 42

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 -

A.

<<<

B.

>>>

C.

>>

D.

<<

Full Access
Question # 43

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

def idler ( ):

XXX

A.

pass

B.

return

C.

exit

D.

None

Full Access
Question # 44

Python strings can be “glued” together using the operator:

A.

.

B.

&

C.

_

D.

+

Full Access
Question # 45

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

A.

except Ex1 Ex2:

B.

except (ex1, Ex2):

C.

except Ex1, Ex2:

D.

except Ex1+Ex2:

Full Access
Question # 46

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

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

Full Access