Certified Associate in Python Programming Sample Questions
PCAP™ – Certified Associate in Python Programming certification focuses on the Object-Oriented Programming technique to Python, and shows that the candidate is acquainted with the greater superior components of programming, including the essentials of OOP, the necessities of modules and programs, the exception dealing with a mechanism in OOP, advanced operations on strings, list comprehensions, lambdas, generators, closures, and file processing.
PCAP™ certification gives its holders self-belief in their programming talents, facilitates them to stand out in the process marketplace, and offers them a head beginning on getting ready for and advancing to the expert level.
PCAP™ – Certified Associate in Python Programming certification (Exam PCAP-31-0x) is an expert, excessive-stakes credential that measures the candidate’s ability to carry out intermediate-degree coding responsibilities within the Python language, which includes the capacity to design, expand, debug, execute, and refactor multi-module Python programs, in addition to measures their capabilities and know-how associated with studying and modeling actual-existence problems in OOP classes with the usage of the fundamental notions and strategies available in the object-oriented technique.
What is the output of the following code?
makefileCopy codex = "Hello"
y = "World"
print(x + y)
- a. Hello World
- b. HelloWorld
- c. Hello+World
- d. Error
Answer: a. Hello World
Explanation: The + operator can be used to concatenate two strings in Python.
Which of the following is an example of a Boolean value in Certified Associate in Python Programming?
- a. “Hello”
- b. 123
- c. True
- d. 3.14
Answer: c. True
Explanation: Boolean values in Python are either True or False.
What is the output of the following code?
pythonCopy codex = 10
if x > 5:
print("x is greater than 5")
else:
print("x is less than or equal to 5")
- a. x is greater than 5
- b. x is less than or equal to 5
- c. Error
- d. Nothing is printed
Answer: a. x is greater than 5
Explanation: The if statement in Python is used to conditionally execute code based on a Boolean expression. In this case, the code in the if block is executed because the condition x > 5 is True.
What is the output of the following code?
cssCopy codemy_list = [1, 2, 3, 4, 5]
for item in my_list:
print(item)
- a. 1 2 3 4 5
- b. [1, 2, 3, 4, 5]
- c. 5 4 3 2 1 d. Error
Answer: a. 1 2 3 4 5
Explanation: The for loop in Python is used to iterate over a sequence (such as a list) and execute a block of code for each item in the sequence. In this case, the print statement is executed for each item in the list, resulting in the output 1 2 3 4 5.
What is the output of the following code?
pythonCopy codedef my_function(x, y):
return x + y
result = my_function(3, 4)
print(result)
- a. 3 4
- b. 7
- c. my_function(3, 4)
- d. Error
Answer: b. 7
Explanation: The code defines a function called my_function that takes two arguments (x and y) and returns their sum. The function is then called with the arguments 3 and 4, and the result (7) is printed to the console.
What is the output of the following code?
goCopy codex = 5
y = 2
print(x // y)
Answer: The output of the code is 2.
Explanation: The //
operator is used for integer division. In this code, x
is divided by y
using the //
operator, which gives the result 2
.
What is the output of the following code?
scssCopy codemy_list = [2, 5, 3, 7, 1]
print(max(my_list))
Answer: The output of the code is 7.
Explanation: The max()
function returns the largest value in the list my_list
, which is 7.
What is the output of the following code?
makefileCopy codemy_string = "hello"
print(my_string[1:4])
Answer: The output of the code is “ell”.
Explanation: The slice notation my_string[1:4]
returns the substring of my_string
that starts at index 1 and ends at index 4 (exclusive), which is “ell”.
What is the output of the following code?
pythonCopy codex = 10
if x > 5:
print("x is greater than 5")
else:
print("x is less than or equal to 5")
Answer: The output of the code is “x is greater than 5”.
Explanation: The if
statement checks if x
is greater than 5. Since x
is equal to 10, which is greater than 5, the first print
statement is executed.
What is the output of the following code?
pythonCopy codedef multiply(x, y):
return x * y
result = multiply(3, 4)
print(result)
Answer: The output of the code is 12.
Explanation: The multiply()
function takes two arguments x
and y
and returns their product. The function is called with arguments 3 and 4, which results in a return value of 12. The value of result
is then printed, which is 12.
1.) The following expression –
1+2 is:
A. Identical to at least one
B. Invalid
C. Identical to two
D. Equal to -1
Right Answer: D
2.) And operator capable of carrying out bitwise shifts is coded as (Choose .)
A. —
B. ++
C. <<
D. >>
Right Answer: CD
Explanation: Python Operators
3.) A compiler is a program designed to (Choose two.)
A. Reorganize the source code to make it clearer
B. check the source code to see if it is correct
C. run the source code
D. translate source code into machine code
Right Answer: BD
4.) What can be the outcome of the given code in Certified Associate in Python Programming?
- a= ‘ant’
- b= “bat”
- c= ‘camel’
- print(a,b,c, sep='”‘)
A. antג€batג€ camel
B. ant’ bat’ camel
C. print (a, b, c, sep= ‘ ג€ ‘)
D. antbatcamel
Right Answer: A
5.) Which of the accompanying assertions are valid? (Pick two.)
A. Python strings are really records
B. Python strings can be linked
C. Python strings can be cut like records
D. Python strings are variable
Right Answer: BC
6.) Which of the accompanying sentences are valid? (Pick two.)
A. Records may not be put away inside tuples
B. Tuples might be put away inside records
C. Tuples may not be put away inside tuples
D. Records might be put away inside records
Right Answer: BD
7.) Expecting that the String is at least six letters in length, the accompanying slice
string[1-2] is more limited than the first string by:
A. three chars
B. four chars
C. one char
D. two chars
Right Answer: A
8.) What can be the expected outcome/result of the given snippet?
- 1st = [1,2,3,4]
- 1st = [-3:-2]
- 1st = 1st[-1]
- print (1st)
A. three
B. four
C. one
D. two
Right answer: D
9.) What do you think can be the expected outcome of the following snippet?
- s= ‘abc’
- for i in len(s)
- s[i] = s[i].upper()
- print(s)
A. The code will cause a runtime exception
B. 123
C. abc
D. ABC
Right answer: A
10.) According to the given snippet below, how many elements will the list2 list contain after it’s execution?
- list1 = [False for i in range (1,10)]
- list2 = list1 [-1:1:-1]
A. seven
B. five
C. three
D. zero
Right answer: A
11.) Supposedely, you are in need of a data which can act as a simple telephone directory, and you can obtain it with the given clauses. (choose any 2)
A. dir= {‘Mom’: ‘5551234567’, ‘Dad’: ‘5557654321’}
B. dir={‘Mom’: 5551234567, ‘Dad’: 5557654321}
C. dir= {Mom: ‘5551234567’, Dad: ‘5557654321’}
D. dir= {Mom: 5551234567, Dad: 5557654321}
Right answer: AB
12.) Could a module at any point run like standard code?
A. indeed, and it can separate its conduct between the customary send off and import
B. it relies upon the Python variant
C. indeed, yet in can’t separate its conduct between the standard send off and import
D. no, it is preposterous; a module can be imported, not run
Right Answer: A
13.) Select the substantial () invocations:
(Pick two.)
- def fun (a,b=0)
- return a*b
A. fun (b=1)
B. fun (a=0)
C. fun (b=1, 0)
D. fun (1)
Right Answer: BD
14.) A record name like this one beneath says that:
(Pick three.)
services, cpython 36.pyc
A. the interpreter used to produce the document is form 3.6
B. it has been delivered by CPython
C. it is the 36 variant of the record
D. the record comes from the services.py source document
Right Answer: ABD
15.) What can be the expected behavior of the given snippet?
def a (1, I) :
return 1 [I]
print (a (0, [1) )
A. it will cause a runtime exception
B. print 0, [1]
C. print 1
D. print [1]
Right answer: A
16.) What else is there to do in the event that you could do without a long package path like this one?
A. you can make an alias for the name utilizing the alias keyword
B. nothing, you really want to come to terms with it
C. you can abbreviate it to alpha . zeta and Python will track down the proper connection
D. you can make an alias for the name utilizing the as a keyword
Right Answer: D
Explanation: Defining aliases for imported modules in python
17.) What do you think will be the expected output of the following code?
- str = ‘abcdef’
- def fun (s) :
- del s [2]
- return s
- print ( fun(str) )
A. The program will cause a runtime exception/error
B. abcef
C. acdef
D. abdef
18.) Is it conceivable to securely check if a class/object has a specific quality?
A. Yes, by utilizing the hasattr attribute
B. Yes, by utilizing the hasattr ( ) method
C. Yes, by utilizing the hassattr ( ) function
D. no, it is unimaginable
Right Answer: C
19.) The primary parameter of every method:
A. holds a reference to the presently handled object
B. is constantly set to None
C. is set by the first argument’s value
D. is set to a unique random value
Right Answer: A
20.) What do you think will be the simplest class definition in python expressed as?
A. class X:
B. class X: pass
C. class X: return
D. class X: { }
Right Answer: A