Skip to main content

PCAP-31-03 Real Exam Questions

PCAP - Certified Associate in Python Programming

153 questions available · Page 1 of 16

Updated Exam DumpsVerified AnswersPass Guarantee

Get Complete Exam Dumps
Question 1 Multiple choice

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

  1. A

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

  2. B

    len(""" """) > 0

  3. C

    chr(ord(`a') + 1) == `B'

  4. D

    len(`\'') == 1

Show answer and explanation

Correct answers: B, D

Explanation

The length of a string containing a space is greater than zero. The escape sequence for a single quote represents one character, so its string length is 1. The other expressions are false because character codes and case-sensitive comparisons do not produce the expected values.

Question 2 Single choice

The simplest possible class definition in Python can be expressed as:

  1. A

    class X:

  2. B

    class X: pass

  3. C

    class X: return

  4. D

    class X: { }

Show answer and explanation

Correct answer: B

Explanation

A class statement must contain a syntactically valid suite. pass is a valid statement that deliberately performs no action, so class X: pass defines an otherwise empty class. A header with no suite is incomplete, return is not valid at class scope, and braces do not serve as an empty class body in Python.

Question 3 Single choice

The first parameter of each method:

  1. A

    holds a reference to the currently processed object

  2. B

    is always set to None

  3. C

    is set to a unique random value

  4. D

    is set by the first argument's value

Show answer and explanation

Correct answer: A

Explanation

For an ordinary instance method, Python supplies the object used for the method call as the first parameter. Conventionally named self, that parameter holds a reference to the currently processed object and allows access to its attributes and methods. It is determined by method binding, not by None or a random value.

Question 4 Multiple choice

Which of the following literals reflect the value given as 34.23? (Select two answers)

  1. A

    .3423e2

  2. B

    3423e-2

  3. C

    .3423e-2

  4. D

    3423e2

Show answer and explanation

Correct answers: A, B

Explanation

Scientific notation multiplies the coefficient by 10 raised to the exponent. The literal .3423e2 evaluates to 0.3423 times 100, which is 34.23. The literal 3423e-2 evaluates to 3423 times 0.01, also 34.23. Reversing those exponent signs produces values with different decimal positions.

Question 5 Single choice

What is the expected behavior of the following code?

  1. A

    it raises an exception

  2. B

    it outputs 0

  3. C

    it outputs 3

  4. D

    it outputs `None'

Show answer and explanation

Correct answer: B

Explanation

Each loop iteration prepends the current character to dummy, so the text representation of the fraction is reversed. The last character of that reversed string is consequently the first character of the original representation. That original representation begins with 0, so indexing dummy at its final position outputs 0.

Question 6 Single choice

What is the expected output of the following snippet?

  1. A

    True lower

  2. B

    True upper

  3. C

    False upper

  4. D

    False lower

Show answer and explanation

Correct answer: B

Explanation

Object is constructed as an instance of Lower, so isinstance(Object, Lower) evaluates to True. The Lower initializer explicitly calls super().__init__(), which runs Upper.__init__ and assigns 'upper' to the inherited instance property. The two prints consequently produce True upper.

Question 7 Single choice

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?

  1. A

    print (get(self))

  2. B

    print (self.get())

  3. C

    print (get())

  4. D

    print (self.get (val))

Show answer and explanation

Correct answer: B

Explanation

get is an instance method, so show must access it through the current instance. In self.get(), Python binds self automatically and the method returns self.val. Passing that result to print displays the stored value. An unqualified get() is not resolved as another method of the instance.

Question 8 Single choice

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

  1. A

    __upper__

  2. B

    __super__

  3. C

    __ancestors__

  4. D

    __bases__

Show answer and explanation

Correct answer: D

Explanation

A class's __bases__ attribute records its direct superclasses. Its value is a tuple containing the actual base class objects in the order used in the class declaration. Because it stores class objects rather than names, identifiers, or memory locations, it can be used directly for inheritance introspection, including examining each base class's own attributes.

Question 9 Multiple choice

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

  1. A

    open () is a function which returns an int that represents a physical file handle

  2. B

    the second open () argument is optional

  3. C

    instd, outstd, errstd are the names of pre-opened streams

  4. D

    if invoking open () fails, the value None is returned

Show answer and explanation

Correct answers: B, C

Explanation

The second argument of open() is optional because the default mode is "r" (read mode). The standard streams are named stdin, stdout, and stderr and are automatically opened by the operating system. The open() function returns a file object, not an integer file handle, and it raises an exception if opening the file fails instead of returning None.

Question 10 Multiple choice

Which of the following statements are true? (Choose two.)

  1. A

    if invoking open () fails, an exception is raised

  2. B

    open () requires a second argument

  3. C

    open () is a function which returns an object that represents a physical file

  4. D

    instd, outstd. errstd are the names of pre-opened streams

Show answer and explanation

Correct answers: A, C

Explanation

open() attempts to establish access to a file, and a failure such as an unavailable path or disallowed mode raises an exception. On success, it returns a file object representing the opened file and providing operations such as read, write, and close. Its mode argument is optional because it defaults to reading; the standard stream names are stdin, stdout, and stderr.