Exam4Training

Python Institute PCAP-31-03 Certified Associate in Python Programming Exam Online Training

Question #1

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")

Reveal Solution Hide Solution

Correct Answer: C
Question #2

With regards to the directory structure below, select the proper forms of the directives in order to import module_a. (Select two answers)

  • A . import pypack.module_a
  • B . import module_a from pypack
  • C . import module_a
  • D . from pypack import module_a

Reveal Solution Hide Solution

Correct Answer: A,D
Question #3

You are going to read 16 bytes from a binary file into a bytearray called data .

Which lines would you use?

  • 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))

Reveal Solution Hide Solution

Correct Answer: D
D

Explanation:

https://docs.python.org/3/library/functions.html#func-bytearray https://docs.python.org/3/library/io.html

Question #4

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

Reveal Solution Hide Solution

Correct Answer: C,D
Question #5

The__bases__property contains:

  • A . base class locations (addr)
  • B . base class objects (class)
  • C . base class names (str)
  • D . base class ids (int)

Reveal Solution Hide Solution

Correct Answer: B
Question #6

The following class hierarchy is given .

What is the expected out of the code?

  • A . BB
  • B . CC
  • C . AA
  • D . BC

Reveal Solution Hide Solution

Correct Answer: D
Question #7

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

  • A . sequential
  • B . named
  • C . positional
  • D . keyword

Reveal Solution Hide Solution

Correct Answer: C
Question #8

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

  • A . except Exception(e):
  • B . except e=Exception:
  • C . except Exception as e:
  • D . such an action is not possible in Python

Reveal Solution Hide Solution

Correct Answer: C
C

Explanation:

Reference: https://stackoverflow.com/questions/32613375/python-2-7-exception-handling-syntax

Question #9

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

  • A . encapsulation allows you to protect some data from uncontrolled access
  • B . the arrows on a class diagram are always directed from a superclass towards its
    subclass
  • C . inheritance is the relation between a superclass and a subclass
  • D . an object is a recipe for a class

Reveal Solution Hide Solution

Correct Answer: A,C
Question #10

What is the expected behavior of the following code?

  • A . It outputs False
  • B . It outputs nothing
  • C . It outputs True
  • D . It raises an exception

Reveal Solution Hide Solution

Correct Answer: A

Question #11

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:

Reveal Solution Hide Solution

Correct Answer: B
Question #12

What is the expected behavior of the following code?

It will:

  • A . print 0
  • B . cause a runtime exception
  • C . prints 3
  • D . print an empty line

Reveal Solution Hide Solution

Correct Answer: B
Question #13

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

Reveal Solution Hide Solution

Correct Answer: C,D
Question #14

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

Reveal Solution Hide Solution

Correct Answer: A ,D
Question #15

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

Reveal Solution Hide Solution

Correct Answer: B
Question #16

What is the expected behavior of the following code?

  • A . it outputs ‘None’
  • B . it outputs 3
  • C . it raises an exception
  • D . it outputs 0

Reveal Solution Hide Solution

Correct Answer: B
Question #17

What is the expected behavior of the following code?

  • A . it outputs [1, 3]
  • B . the code is erroneous and it will not execute
  • C . it outputs [3, 1]
  • D . it outputs [4, 2, 0]

Reveal Solution Hide Solution

Correct Answer: A
Question #18

What is the expected behavior of the following code?

  • A . it outputs 2
  • B . the code is erroneous and it will not execute
  • C . it outputs 1
  • D . it outputs 3

Reveal Solution Hide Solution

Correct Answer: C
Question #19

What is the expected output of the following snippet?

  • A . 3
  • B . 1
  • C . 2
  • D . the code is erroneous

Reveal Solution Hide Solution

Correct Answer: A
Question #20

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

  • A . a ( ) == 4
  • B . a is not None
  • C . b ( ) == 4
  • D . a ! = b

Reveal Solution Hide Solution

Correct Answer: B,D

Question #21

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

  • A . open () is a function which returns an int that represents a physical file handle
  • B . the second open () argument is optional
  • C . instd, outstd, errstd are the names of pre-opened streams
  • D . if invoking open () fails, the value None is returned

Reveal Solution Hide Solution

Correct Answer: A,B
Question #22

What is the expected output of the following snippet?

  • A . 1
  • B . 4
  • C . 2
  • D . 3

Reveal Solution Hide Solution

Correct Answer: C
Question #23

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

Reveal Solution Hide Solution

Correct Answer: D
D

Explanation:

Reference: https://dev.to/ogwurujohnson/distinguishing-instance-variables-from-class-variables-in-python-81

Question #24

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

  • A . a is not None
  • B . a ! =b
  • C . b () ==4
  • D . a () == 4

Reveal Solution Hide Solution

Correct Answer: A,B
Question #25

What is the expected behavior of the following code?

  • A . it outputs list assignment index out of range
  • B . the code is erroneous and it will not execute
  • C . it outputs <class ‘IndexError’>
  • D . it outputs error

Reveal Solution Hide Solution

Correct Answer: A
Question #26

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

Reveal Solution Hide Solution

Correct Answer: A,B
Question #27

What is the expected behavior of the following code?

  • A . it outputs 2
  • B . the code is erroneous and it will not execute
  • C . it outputs 3
  • D . it outputs :

Reveal Solution Hide Solution

Correct Answer: D
Question #28

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

  • A . the__name__variable content determines the way in which the module was run
  • B . a package can be stored as a tree of sub-directories/sub-folders
  • C . __pycache__is the name of a built-in variable
  • D . hashbang is the name of a built-in Python function

Reveal Solution Hide Solution

Correct Answer: B,C
Question #29

What is the expected output of the following code?

  • A . abcef
  • B . The program will cause a runtime exception error
  • C . acdef
  • D . abdef

Reveal Solution Hide Solution

Correct Answer: B
Question #30

A Python module named pymod, py contains a function named pyfun ( ).

Which of the following snippets will let you invoke the function? (Select two answers)

  • A . From pymod import ‘
    Pymod.pyfun ( )
  • B . Import pymod
    Pymod. Pyfun ( )
  • C . Import pyfun from pymod
    Pyfun ( )
  • D . From pymod import pyfun
    Pyfun ( )

Reveal Solution Hide Solution

Correct Answer: B,D

Question #31

You need data which can act as a simple telephone directory. You can obtain it with the following clauses (choose two relevant variants; assume that no other items have been created before)

  • A . dir={‘Mom’:5551234567, ‘Dad’:5557654321>
  • B . dir={‘Mom’:’5551234567′, * Dad’:’5557654321′}
  • C . dir={Mom:5551234567, Dad:5557654321}
  • D . dir={Mom:’5551234567′, Dad:’5557654321′}

Reveal Solution Hide Solution

Correct Answer: C D
Question #32

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

  • A . sorted ("python”)
  • B . "python" .sort ( )
  • C . sort" ("python")
  • D . "python’ ,find (")

Reveal Solution Hide Solution

Correct Answer: A,D
Question #33

What is the expected behavior of the following code?

  • A . it outputs 1
  • B . it outputs 0
  • C . it raises an exception
  • D . it outputs 2

Reveal Solution Hide Solution

Correct Answer: A
Question #34

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

  • A . 2 2
  • B . 1 3
  • C . 1 2 3
  • D . 2 2 3

Reveal Solution Hide Solution

Correct Answer: A
Question #35

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

  • A . 10
  • B . the variable becomes unavailable
  • C . 11
  • D . 9

Reveal Solution Hide Solution

Correct Answer: D
D

Explanation:

Pass only means there are no statements to execute it does not means the variable is unavailable. Try a Print statement Print(i) after the For Loop and there is your result.

Question #36

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)

Reveal Solution Hide Solution

Correct Answer: A,B
Question #37

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.

Reveal Solution Hide Solution

Correct Answer: A,C
Question #38

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

  • A . ‘var’ in Object.__dict__
  • B . ‘prop’ in Class.__dict
  • C . len(Object.__diet__) == 1
  • D . ‘var1 in Class, dict

Reveal Solution Hide Solution

Correct Answer: A,C
Question #39

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

  • A . str(1-1) in ‘012345£739′[:2]
  • B . ‘phd’ in ‘alpha’
  • C . ‘deb’ not in ‘abcde’ [::-1]
  • D . ‘True’ not in ‘False’

Reveal Solution Hide Solution

Correct Answer: C,D
Question #40

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

  • A . 1
  • B . 0
  • C . 2
  • D . the variable becomes unavailable

Reveal Solution Hide Solution

Correct Answer: A

Question #41

What is the expected behavior of the following code?

  • A . it outputs 1
  • B . it outputs 2
  • C . the code is erroneous and it will not execute
  • D . it outputs 3

Reveal Solution Hide Solution

Correct Answer: B
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 . <<

Reveal Solution Hide Solution

Correct Answer: C
Question #43

What can you do if you don’t like a long package path like this one?

  • A . you can make an alias for the name using the alias 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 the as keyword

Reveal Solution Hide Solution

Correct Answer: D
D

Explanation:

Reference: https://stackoverflow.com/questions/706595/can-you-define-aliases-for-imported-modules-in-python

Question #44

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

  • A . – –
  • B . ++
  • C . <<
  • D . >>

Reveal Solution Hide Solution

Correct Answer: C,D
C,D

Explanation:

Reference: https://www.geeksforgeeks.org/basic-operators-python/

Question #45

What is the expected output of the following snippet?

  • A . abc
  • B . The code will cause a runtime exception
  • C . ABC
  • D . 123

Reveal Solution Hide Solution

Correct Answer: B
Question #46

The following expression

1+-2

is:

  • A . equal to 1
  • B . invalid
  • C . equal to 2
  • D . equal to -1

Reveal Solution Hide Solution

Correct Answer: D
Question #47

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

  • A . put self.store(1])
  • B . self put stire(1])
  • C . self .put self.get () [-1])
  • D . self .put (self.store[1])

Reveal Solution Hide Solution

Correct Answer: B,D
Question #48

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) )

  • A . 1
  • B . 0
  • C . -1
  • D . an exception is raised

Reveal Solution Hide Solution

Correct Answer: C
Question #49

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

Reveal Solution Hide Solution

Correct Answer: A,B
Question #50

What is the expected output of the following code?

  • A . 3
  • B . 5
  • C . 4
  • D . an exception is raised

Reveal Solution Hide Solution

Correct Answer: A
Exit mobile version